Part Number Hot Search : 
C1206 BRY56B 10N50 20CIH07B 02012 SPA257 6200T5LC TGT100
Product Description
Full Text Search
 

To Download PIC16F871T-EL Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2003 microchip technology inc. ds30569b pic16f870/871 data sheet 28/40-pin, 8-bit cmos flash microcontrollers
ds30569b-page ii ? 2003 microchip technology inc. information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. it is your responsibility to ensure that your application m eets with your specifications. no representation or warranty is given and no liability is assumed by microchip technol ogy incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. use of mi crochip?s products as critical components in life support syst ems is not authorized except with express written approval by microchip. no licenses are conveyed, implicitly or ot herwise, under any intellectual property rights. trademarks the microchip name and logo, the microchip logo, k ee l oq , mplab, pic, picmicro, picstart, pro mate and powersmart are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, micro id , mxdev, mxlab, picmaster, seeval and the embedded control solutions company are registered trademarks of micr ochip technology incorporated in the u.s.a. accuron, application maestro, dspic, dspicdem, dspicdem.net, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, microport, migratable memory, mpasm, mplib, mplink, mpsim, picc, pickit, picdem, picdem.net, powercal, powerinfo, powermate, powertool, rflab, rfpic, select mode, smartsensor, smartshunt, smarttel and total endurance are trademarks of microchip technology incorporated in the u.s.a. and other countries. serialized quick turn programming (sqtp) is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned he rein are property of their respective companies. ? 2003, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices:  microchip products meet the specification cont ained in their particular microchip data sheet.  microchip believes that its family of products is one of the most secure families of its kind on the market today, when used i n the intended manner and under normal conditions.  there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specifications contained in microchip's data sheets. most likely, the person doing so is engaged in theft of intellectual property.  microchip is willing to work with the customer who is concerned about the integrity of their code.  neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are comm itted to continuously improving the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received qs-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona in july 1999 and mountain view, california in march 2002. the company?s quality system processes and procedures are qs-9000 compliant for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, non-volatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001 certified.
? 2003 microchip technology inc. ds30569b-page 1 pic16f870/871 devices included in this data sheet: microcontroller core features:  high performance risc cpu  only 35 single word instructions to learn  all single cycle instructions except for program branches which are two-cycle  operating speed: dc - 20 mhz clock input dc - 200 ns instruction cycle  2k x 14 words of flash program memory 128 x 8 bytes of data memory (ram) 64 x 8 bytes of eeprom data memory  pinout compatible to the pic16cxxx 28 and 40-pin devices  interrupt capability (up to 11 sources)  eight level deep hardware stack  direct, indirect and relative addressing modes  power-on reset (por)  power-up timer (pwrt) and oscillator start-up timer (ost)  watchdog timer (wdt) with its own on-chip rc oscillator for reliable operation  programmable code protection  power saving sleep mode  selectable oscillator options  low power, high speed cmos flash/eeprom technology  fully static design  in-circuit serial programming ? (icsp ? ) via two pins  single 5v in-circuit serial programming capability  in-circuit debugging via two pins  processor read/write access to program memory  wide operating voltage range: 2.0v to 5.5v  high sink/source current: 25 ma  commercial and industrial temperature ranges  low power consumption: - < 1.6 ma typical @ 5v, 4 mhz -20 a typical @ 3v, 32 khz -< 1 a typical standby current pin diagram peripheral features:  timer0: 8-bit timer/counter with 8-bit prescaler  timer1: 16-bit timer/counter with prescaler, can be incremented during sleep via external crystal/clock  timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler  one capture, compare, pwm module - capture is 16-bit, max. resolution is 12.5 ns - compare is 16-bit, max. resolution is 200 ns - pwm max. resolution is 10-bit  10-bit multi-channel analog-to-digital converter  universal synchronous asynchronous receiver transmitter (usart/sci) with 9-bit address detection  parallel slave port (psp) 8-bits wide, with external rd , wr and cs controls (40/44-pin only)  brown-out detection circuitry for brown-out reset (bor) pic16f870 pic16f871 rb7/pgd rb6/pgc rb5 rb4 rb3/pgm rb2 rb1 rb0/int v dd v ss rd7/psp7 rd6/psp6 rd5/psp5 rd4/psp4 rc7/rx/dt rc6/tx/ck rc5 rc4 rd3/psp3 rd2/psp2 mclr /v pp /thv ra0/an0 ra1/an1 ra2/an2/v ref - ra3/an3/v ref + ra4/t0cki ra5/an4 re0/rd /an5 re1/wr /an6 re2/cs /an7 v dd v ss osc1/clki osc2/clko rc0/t1oso/t1cki rc1/t1osi rc2/ccp1 rc3 rd0/psp0 rd1/psp1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 pic16f871 pdip 28/40-pin, 8-bit cmos flash microcontrollers
pic16f870/871 ds30569b-page 2 ? 2003 microchip technology inc. pin diagrams pic16f870 10 11 2 3 4 5 6 1 8 7 9 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 22 21 mclr /v pp /thv ra0/an0 ra1/an1 ra2/an2/v ref - ra3/an3/v ref + ra4/t0cki ra5/an4 v ss osc1/clki osc2/clko rc0/t1oso/t1cki rc1/t1osi rc2/ccp1 rc3 rb7/pgd rb6/pgc rb5 rb4 rb3/pgm rb2 rb1 rb0/int v dd v ss rc7/rx/dt rc6/tx/ck rc5 rc4 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 44 8 7 6 5 4 3 2 1 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 9 pic16f871 ra4/t0cki ra5/an4 re0/rd /an5 osc1/clki osc2/clko rc0/t1oso/t1ck1 nc re1/wr /an6 re2/cs /an7 v dd v ss rb3/pgm rb2 rb1 rb0/int v dd v ss rd7/psp7 rd6/psp6 rd5/psp5 rd4/psp4 rc7/rx/dt ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 mclr /v pp /thv nc rb7/pgd rb6/pgc rb5 rb4 nc nc rc6/tx/ck rc5 rc4 rd3/psp3 rd2/psp2 rd1/psp1 rd0/psp0 rc3 rc2/ccp1 rc1/t1osi 10 11 2 3 4 5 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 pic16f871 37 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 mclr /v pp /thv nc rb7/pgd rb6/pgc rb5 rb4 nc rc6/tx/ck rc5 rc4 rd3/psp3 rd2/psp2 rd1/psp1 rd0/psp0 rc3 rc2/ccp1 rc1/t1osi nc nc rc0/t1oso/t1cki osc2/clko osc1/clki v ss v dd re2/cs /an7 re1/wr /an6 re0/rd /an5 ra5/an4 ra4/t0cki rc7/rx/dt rd4/psp4 rd5/psp5 rd6/psp6 rd7/psp7 v ss v dd rb0/int rb1 rb2 rb3/pgm plcc tqfp dip, soic, ssop
? 2003 microchip technology inc. ds30569b-page 3 pic16f870/871 key features picmicro tm mid-range mcu family reference manual (ds33023) pic16f870 pic16f871 operating frequency dc - 20 mhz dc - 20 mhz resets (and delays) por, bor (pwrt, ost) por, bor (pwrt, ost) flash program memory (14-bit words) 2k 2k data memory (bytes) 128 128 eeprom data memory 64 64 interrupts 10 11 i/o ports ports a,b,c ports a,b,c,d,e timers 3 3 capture/compare/pwm modules 1 1 serial communications usart usart parallel communications ? psp 10-bit analog-to-digital module 5 input channels 8 input channels instruction set 35 instructions 35 instructions
pic16f870/871 ds30569b-page 4 ? 2003 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 5 2.0 memory organization ......................................................................................................... ........................................................ 11 3.0 data eeprom and flash program memory........................................................................................ ...................................... 27 4.0 i/o ports ................................................................................................................... .................................................................. 33 5.0 timer0 module ............................................................................................................... ............................................................ 45 6.0 timer1 module ............................................................................................................... ............................................................ 49 7.0 timer2 module ............................................................................................................... ............................................................ 53 8.0 capture/compare/pwm modules ................................................................................................. ............................................. 55 9.0 addressable universal synchronous asynchr onous receiver transmitter (usart)................................................. ............... 61 10.0 analog-to-digital (a/d) converter module ................................................................................... ............................................... 79 11.0 special features of the cpu ................................................................................................ ...................................................... 87 12.0 instruction set summary .................................................................................................... ...................................................... 103 13.0 development support........................................................................................................ ....................................................... 111 14.0 electrical characteristics ................................................................................................. ......................................................... 117 15.0 dc and ac characteristics graphs and tables ................................................................................ ....................................... 137 16.0 packaging information...................................................................................................... ........................................................ 149 appendix a: revision history................................................................................................... .......................................................... 157 appendix b: device differences................................................................................................. ........................................................ 157 appendix c: conversion considerations .......................................................................................... ................................................. 158 appendix d: migration from mid-range to enhanced devices ....................................................................... ................................... 158 appendix e: migration from high-end to enhanced devices........................................................................ ..................................... 159 index .......................................................................................................................... ........................................................................ 161 on-line support................................................................................................................ ................................................................. 167 systems information and upgrade hot line ....................................................................................... ............................................... 167 reader response ................................................................................................................ .............................................................. 168 pic16f870/871 product identification system .................................................................................... .............................................. 169 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@mail.microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following:  microchip?s worldwide web site; http://www.microchip.com  your local microchip sales office (see last page)  the microchip corporate literatu re center; u.s. fax: (480) 792-7277 when contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (inclu de literature number) you are using. customer notification system register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
? 2003 microchip technology inc. ds30569b-page 5 pic16f870/871 1.0 device overview this document contains device specific information. additional information may be found in the picmicro tm mid-range mcu family reference manual (ds33023), which may be obtained from your local microchip sales representative or downloaded from the microchip web site. the reference manual should be considered a complementary document to this data sheet, and is highly recommended reading for a better understanding of the device architecture and operation of the peripheral modules. there are two devices (pic16f870 and pic16f871) covered by this data sheet. the pic16f870 device comes in a 28-pin package and the pic16f871 device comes in a 40-pin package. the 28-pin device does not have a parallel slave port implemented. the following two figures are device block diagrams sorted by pin number: 28-pin for figure 1-1 and 40-pin for figure 1-2. the 28-pin and 40-pin pinouts are listed in table 1-1 and table 1-2, respectively. figure 1-1: pic16f870 block diagram flash program memory 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clki osc2/clko mclr v dd , v ss porta portb portc ra4/t0cki ra5/an4 rb0/int rc0/t1oso/t1cki rc1/t1osi rc2/ccp1 rc3 rc4 rc5 rc6/tx/ck rc7/rx/dt 8 8 brown-out reset note 1: higher order bits are from the status register. usart ccp1 10-bit a/d timer0 timer1 timer2 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 8 3 data eeprom rb1 rb2 rb3/pgm rb4 rb5 rb6/pgc rb7/pgd device program flash data memory data eeprom pic16f870 2k 128 bytes 64 bytes in-circuit debugger low-voltage programming
pic16f870/871 ds30569b-page 6 ? 2003 microchip technology inc. figure 1-2: pic16f871 block diagram flash program memory 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clki osc2/clko mclr v dd , v ss porta portb portc portd porte ra4/t0cki ra5/an4 rc0/t1oso/t1cki rc1/t1osi rc2/ccp1 rc3 rc4 rc5 rc6/tx/ck rc7/rx/dt rd7/psp7:rd0/psp0 re0/rd /an5 re1/wr /an6 re2/cs /an7 8 8 brown-out reset note 1: higher order bits are from the status register. usart ccp1 10-bit a/d timer0 timer1 timer2 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 8 3 data eeprom rb0/int rb1 rb2 rb3/pgm rb4 rb5 rb6/pgc rb7/pgd device program flash data memory data eeprom pic16f871 2k 128 bytes 64 bytes in-circuit debugger low-voltage programming parallel slave port
? 2003 microchip technology inc. ds30569b-page 7 pic16f870/871 table 1-1: pic16f870 pinout description pin name dip pin# soic pin# i/o/p type buffer type description osc1/clki 9 9 i st/cmos (3) oscillator crystal input/external clock source input. osc2/clko 10 10 o ? oscillator crystal output. co nnects to crystal or resonator in crystal oscillator mode. in rc mode, the osc2 pin outputs clko, which has 1/4 the frequency of osc1, and denotes the instruction cycle rate. mclr /v pp /thv 1 1 i/p st master clear (reset) input or programming voltage input or high voltage test mode control. this pin is an active low reset to the device. porta is a bi-directional i/o port. ra0/an0 2 2 i/o ttl ra0 can also be analog input 0. ra1/an1 3 3 i/o ttl ra1 can also be analog input 1. ra2/an2/v ref - 4 4 i/o ttl ra2 can also be analog input 2 or negative analog reference voltage. ra3/an3/v ref + 5 5 i/o ttl ra3 can also be analog input 3 or positive analog reference voltage. ra4/t0cki 6 6 i/o st/od ra4 can also be the clock input to the timer0 module. output is open drain type. ra5/an4 7 7 i/o ttl ra5 can also be analog input 4. portb is a bi-directional i/o port. portb can be software programmed for internal weak pull-up on all inputs. rb0/int 21 21 i/o ttl/st (1) rb0 can also be the external interrupt pin. rb1 22 22 i/o ttl rb2 23 23 i/o ttl rb3/pgm 24 24 i/o ttl/st (1) rb3 can also be the low voltage programming input. rb4 25 25 i/o ttl interrupt-on-change pin. rb5 26 26 i/o ttl interrupt-on-change pin. rb6/pgc 27 27 i/o ttl/st (2) interrupt-on-change pin or in-circuit debugger pin. serial programming clock. rb7/pgd 28 28 i/o ttl/st (2) interrupt-on-change pin or in-circuit debugger pin. serial programming data. portc is a bi-directional i/o port. rc0/t1oso/t1cki 11 11 i/o st rc0 can also be the timer1 oscillator output or timer1 clock input. rc1/t1osi 12 12 i/o st rc1 can also be the timer1 oscillator input. rc2/ccp1 13 13 i/o st rc2 can also be the capture1 input/compare1 output/ pwm1 output. rc3 14 14 i/o st rc4 15 15 i/o st rc5 16 16 i/o st rc6/tx/ck 17 17 i/o st rc6 can also be the usart asynchronous transmit or synchronous clock. rc7/rx/dt 18 18 i/o st rc7 can also be the usart asynchronous receive or synchronous data. v ss 8, 19 8, 19 p ? ground reference for logic and i/o pins. v dd 20 20 p ? positive supply for logic and i/o pins. legend: i = input o = output i/o = input/output p = power od = open drain ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt or lvp mode. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: this buffer is a schmitt trigger input when confi gured in rc oscillator mode and a cmos input otherwise.
pic16f870/871 ds30569b-page 8 ? 2003 microchip technology inc. table 1-2: pic16f871 pinout description pin name dip pin# plcc pin# qfp pin# i/o/p type buffer type description osc1/clki 13 14 30 i st/cmos (4) oscillator crystal input/external clock source input. osc2/clko 14 15 31 o ? oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in rc mode, osc2 pin outputs clko, which has 1/4 the frequency of osc1, and denotes the instruction cycle rate. mclr /v pp /thv 1 2 18 i/p st master clear (reset) input or programming voltage input or high voltage test mode control. this pin is an active low reset to the device. porta is a bi-directional i/o port. ra0/an0 2 3 19 i/o ttl ra0 can also be analog input 0. ra1/an1 3 4 20 i/o ttl ra1 can also be analog input 1. ra2/an2/v ref - 4 5 21 i/o ttl ra2 can also be analog input 2 or negative analog reference voltage. ra3/an3/v ref + 5 6 22 i/o ttl ra3 can also be analog input 3 or positive analog reference voltage. ra4/t0cki 6 7 23 i/o st ra4 can also be the clock input to the timer0 timer/counter. output is open drain type. ra5/an4 7 8 24 i/o ttl ra5 can also be analog input 4. portb is a bi-directional i/o port. portb can be software programmed for internal weak pull-up on all inputs. rb0/int 33 36 8 i/o ttl/st (1) rb0 can also be the external interrupt pin. rb1 34 37 9 i/o ttl rb2 35 38 10 i/o ttl rb3/pgm 36 39 11 i/o ttl/st (1) rb3 can also be the low voltage programming input. rb4 37 41 14 i/o ttl interrupt-on-change pin. rb5 38 42 15 i/o ttl interrupt-on-change pin. rb6/pgc 39 43 16 i/o ttl/st (2) interrupt-on-change pin or in-circuit debugger pin. serial programming clock. rb7/pgd 40 44 17 i/o ttl/st (2) interrupt-on-change pin or in-circuit debugger pin. serial programming data. portc is a bi-directional i/o port. rc0/t1oso/t1cki 15 16 32 i/o st rc0 can also be the timer1 oscillator output or a timer1 clock input. rc1/t1osi 16 18 35 i/o st rc1 can also be the timer1 oscillator input. rc2/ccp1 17 19 36 i/o st rc2 can also be the capture1 input/compare1 output/ pwm1 output. rc3 18 20 37 i/o st rc4 23 25 42 i/o st rc5 24 26 43 i/o st rc6/tx/ck 25 27 44 i/o st rc6 can also be the usart asynchronous transmit or synchronous clock. rc7/rx/dt 26 29 1 i/o st rc7 can also be the usart asynchronous receive or synchronous data. legend: i = input o = output i/o = input/output p = power ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input when c onfigured as an external interrupt or lvp mode. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: this buffer is a schmitt trigger input when configured as general purpose i/o and a ttl input when used in the parallel slave port mode (for interfacing to a microprocessor bus). 4: this buffer is a schmitt trigger input when confi gured in rc oscillator mode and a cmos input otherwise.
? 2003 microchip technology inc. ds30569b-page 9 pic16f870/871 portd is a bi-directional i/o port or parallel slave port when interfacing to a microprocessor bus. rd0/psp0 19 21 38 i/o st/ttl (3) rd1/psp1 20 22 39 i/o st/ttl (3) rd2/psp2 21 23 40 i/o st/ttl (3) rd3/psp3 22 24 41 i/o st/ttl (3) rd4/psp4 27 30 2 i/o st/ttl (3) rd5/psp5 28 31 3 i/o st/ttl (3) rd6/psp6 29 32 4 i/o st/ttl (3) rd7/psp7 30 33 5 i/o st/ttl (3) porte is a bi-directional i/o port. re0/rd /an5 8 9 25 i/o st/ttl (3) re0 can also be read control for the parallel slave port, or analog input 5. re1/wr /an6 9 10 26 i/o st/ttl (3) re1 can also be write control for the parallel slave port, or analog input 6. re2/cs /an7 10 11 27 i/o st/ttl (3) re2 can also be select control for the parallel slave port, or analog input 7. v ss 12,31 13,34 6,29 p ? ground reference for logic and i/o pins. v dd 11,32 12,35 7,28 p ? positive supply for logic and i/o pins. nc ? 1,17,28, 40 12,13, 33,34 ? these pins are not internally connected. these pins should be left unconnected. table 1-2: pic16f871 pinout description (continued) pin name dip pin# plcc pin# qfp pin# i/o/p type buffer type description legend: i = input o = output i/o = input/output p = power ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input when c onfigured as an external interrupt or lvp mode. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: this buffer is a schmitt trigger input when configured as general purpose i/o and a ttl input when used in the parallel slave port mode (for interfacing to a microprocessor bus). 4: this buffer is a schmitt trigger input when confi gured in rc oscillator mode and a cmos input otherwise.
pic16f870/871 ds30569b-page 10 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 11 pic16f870/871 2.0 memory organization the pic16f870/871 devices have three memory blocks. the program memory and data memory have separate buses, so that concurrent access can occur, and is detailed in this section. the eeprom data memory block is detailed in section 3.0. additional information on device memory may be found in the picmicro tm mid-range mcu family reference manual (ds33023). 2.1 program memory organization the pic16f870/871 devices have a 13-bit program counter capable of addressing an 8k x 14 program memory space. the pic16f870/871 devices have 2k x 14 words of flash program memory. accessing a location above the physically implemented address will cause a wraparound. the reset vector is at 0000h and the interrupt vector is at 0004h. figure 2-1: pic16f870/871 program memory map and stack 2.2 data memory organization the data memory is partitioned into multiple banks which contain the general purpose registers and the special function registers. bits rp1 (status<6>) and rp0 (status<5>) are the bank select bits. each bank extends up to 7fh (128 bytes). the lower locations of each bank are reserved for the special function registers. above the special function regis- ters are general purpose registers, implemented as static ram. all implemented banks contain special function registers. some ?high use? special function registers from one bank may be mirrored in another bank for code reduction and quicker access. 2.2.1 general purpose register file the register file can be accessed either directly, or indirectly through the file select register fsr. pc<12:0> 13 0000h 0004h 0005h stack level 1 stack level 8 reset vector interrupt vector on-chip call, return retfie, retlw 1fffh stack level 2 program memory page 0 07ffh 0800h rp<1:0> bank 00 0 01 1 10 2 11 3 note: eeprom data memory description can be found in section 3.0 of this data sheet.
pic16f870/871 ds30569b-page 12 ? 2003 microchip technology inc. figure 2-2: pic16f870/871 register file map indirect addr. (*) tmr0 pcl status fsr porta portb portc pclath intcon pir1 tmr1l tmr1h t1con tmr2 t2con ccpr1l ccpr1h rcsta option_reg pcl status fsr trisa trisb trisc pclath intcon pie1 pcon pr2 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1ch 1dh 1eh 1fh 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 file address indirect addr. (*) indirect addr. (*) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h 101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh 17fh 1ffh bank 2 bank 3 indirect addr. (*) adresl tmr0 option_reg pir2 pie2 adresh adcon0 adcon1 general purpose register general purpose register 1efh 1f0h accesses a0h - bfh 16fh 170h accesses 70h-7fh trisb portb 96 bytes 32 bytes 10ch 10dh 10eh 10fh 110h 18ch 18dh 18eh 18fh 190h eedata eeadr eecon1 eecon2 eedath eeadrh reserved (1) reserved (1) unimplemented data memory locations, read as '0'. * not a physical register. note 1: these registers are reserved; maintain these registers clear. 2: these registers are not implemented on the pic16f870. 120h 1a0h accesses 70h-7fh accesses 70h-7fh accesses 20h-7fh c0h efh f0h 1c0h 1bfh bfh txreg rcreg ccp1con txsta spbrg portd (2) porte (2) trisd (2) trise (2) file address file address file address
? 2003 microchip technology inc. ds30569b-page 13 pic16f870/871 2.2.2 special function registers the special function registers are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. a list of these registers is given in table 2-1. the special function registers can be classified into two sets: core (cpu) and peripheral. those registers associated with the core functions are described in detail in this section. those related to the operation of the peripheral features are described in detail in the peripheral feature section. table 2-1: special function register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets (2) bank 0 00h (4) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 0000 0000 01h tmr0 timer0 module?s register xxxx xxxx uuuu uuuu 02h (4) pcl program counter's (pc) least significant byte 0000 0000 0000 0000 03h (4) status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 04h (4) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 05h porta ? ? porta data latch when written: porta pins when read --0x 0000 --0u 0000 06h portb portb data latch when written: portb pins when read xxxx xxxx uuuu uuuu 07h portc portc data latch when written: portc pins when read xxxx xxxx uuuu uuuu 08h (5) portd portd data latch when written: portd pins when read xxxx xxxx uuuu uuuu 09h (5) porte ? ? ? ? ? re2 re1 re0 ---- -xxx ---- -uuu 0ah (1,4) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 0bh (4) intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 pspif (3) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 0dh pir2 ? ? ?eeif ? ? ? ? ---0 ---- ---0 ---- 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu 11h tmr2 timer2 module?s register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 13h ? unimplemented ? ? 14h ? unimplemented ? ? 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 1ah rcreg usart receive data register 0000 0000 0000 0000 1bh ? unimplemented ? ? 1ch ? unimplemented ? ? 1dh ? unimplemented ? ? 1eh adresh a/d result register high byte xxxx xxxx uuuu uuuu 1fh adcon0 adcs1 adcs0 chs2 chs1 chs0 go/done ?adon 0000 00-0 0000 00-0 legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved. shaded locations are unimplemented, read as ?0?. note 1: the upper byte of the program c ounter is not directly accessible. pclath is a holding register for the pc<12:8> whose contents are transferred to the upper byte of the program counter. 2: other (non power-up) resets include external reset through mclr and watchdog timer reset. 3: bits pspie and pspif are reserved on the 28-pin devices; always maintain these bits clear. 4: these registers can be addressed from any bank. 5: portd, porte, trisd and trise are not physically implemented on the 28-pin devices, read as ?0?.
pic16f870/871 ds30569b-page 14 ? 2003 microchip technology inc. bank 1 80h (4) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 0000 0000 81h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 82h (4) pcl program counter's (pc) least significant byte 0000 0000 0000 0000 83h (4) status irp rp1 rp0 to pd zdcc 0001 1xxx 000q quuu 84h (4) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 85h trisa ? ? porta data direction register --11 1111 --11 1111 86h trisb portb data direction register 1111 1111 1111 1111 87h trisc portc data direction register 1111 1111 1111 1111 88h (5) trisd portd data direction register 1111 1111 1111 1111 89h (5) trise ibf obf ibov pspmode ? porte data direction bits 0000 -111 0000 -111 8ah (1,4) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 8bh (4) intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 8ch pie1 pspie (3) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 8dh pie2 ? ? ? eeie ? ? ? ? ---0 ---- ---0 ---- 8eh pcon ? ? ? ? ? ?por bor ---- --qq ---- --uu 8fh ? unimplemented ? ? 90h ? unimplemented ? ? 91h ? unimplemented ? ? 92h pr2 timer2 period register 1111 1111 1111 1111 93h ? unimplemented ? ? 94h ? unimplemented ? ? 95h ? unimplemented ? ? 96h ? unimplemented ? ? 97h ? unimplemented ? ? 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 9ah ? unimplemented ? ? 9bh ? unimplemented ? ? 9ch ? unimplemented ? ? 9dh ? unimplemented ? ? 9eh adresl a/d result register low byte xxxx xxxx uuuu uuuu 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 0--- 0000 0--- 0000 table 2-1: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets (2) legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved. shaded locations are unimplemented, read as ?0?. note 1: the upper byte of the program c ounter is not directly accessible. pclath is a holding register for the pc<12:8> whose contents are transferred to the upper byte of the program counter. 2: other (non power-up) resets include external reset through mclr and watchdog timer reset. 3: bits pspie and pspif are reserved on the 28-pin devices; always maintain these bits clear. 4: these registers can be addressed from any bank. 5: portd, porte, trisd and trise are not physically implemented on the 28-pin devices, read as ?0?.
? 2003 microchip technology inc. ds30569b-page 15 pic16f870/871 bank 2 100h (4) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 0000 0000 101h tmr0 timer0 module?s register xxxx xxxx uuuu uuuu 102h (4) pcl program counter's (pc) least significant byte 0000 0000 0000 0000 103h (4) status irp rp1 rp0 to pd z dc c 0001 1xxx 000q quuu 104h (4) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 105h ? unimplemented ? ? 106h portb portb data latch when written: portb pins when read xxxx xxxx uuuu uuuu 107h ? unimplemented ? ? 108h ? unimplemented ? ? 109h ? unimplemented ? ? 10ah (1,4) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 10bh (4) intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 10ch eedata eeprom data register xxxx xxxx uuuu uuuu 10dh eeadr eeprom address register xxxx xxxx uuuu uuuu 10eh eedath ? ? eeprom data register high byte xxxx xxxx uuuu uuuu 10fh eeadrh ? ? ? eeprom address register high byte xxxx xxxx uuuu uuuu bank 3 180h (4) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 0000 0000 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 182h (4) pcl program counter's (pc) least significant byte 0000 0000 0000 0000 183h (4) status irp rp1 rp0 to pd z dc c 0001 1xxx 000q quuu 184h (4) fsr indirect data memory address pointer xxxx xxxx uuuu uuuu 185h ? unimplemented ? ? 186h trisb portb data direction register 1111 1111 1111 1111 187h ? unimplemented ? ? 188h ? unimplemented ? ? 189h ? unimplemented ? ? 18ah (1,4) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 ---0 0000 18bh (4) intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 18ch eecon1 eepgd ? ? ? wrerr wren wr rd x--- x000 x--- u000 18dh eecon2 eeprom control register2 (not a physical register) ---- ---- ---- ---- 18eh ? reserved maintain clear 0000 0000 0000 0000 18fh ? reserved maintain clear 0000 0000 0000 0000 table 2-1: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets (2) legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved. shaded locations are unimplemented, read as ?0?. note 1: the upper byte of the program c ounter is not directly accessible. pclath is a holding register for the pc<12:8> whose contents are transferred to the upper byte of the program counter. 2: other (non power-up) resets include external reset through mclr and watchdog timer reset. 3: bits pspie and pspif are reserved on the 28-pin devices; always maintain these bits clear. 4: these registers can be addressed from any bank. 5: portd, porte, trisd and trise are not physically implemented on the 28-pin devices, read as ?0?.
pic16f870/871 ds30569b-page 16 ? 2003 microchip technology inc. 2.2.2.1 status register the status register contains the arithmetic status of the alu, the reset status and the bank select bits for data memory. the status register can be the destination for any instruction, as with any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are not writable, therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper three bits and set the z bit. this leaves the status register as 000u u1uu (where u = unchanged). it is recommended, therefore, that only bcf , bsf , swapf and movwf instructions are used to alter the status register, because these instructions do not affect the z, c or dc bits from the status register. for other instructions not affecting any status bits, see the ?instruction set summary?. register 2-1: status register (address: 03h, 83h, 103h, 183h) note 1: the c and dc bits operate as a borrow and digit borrow bit, respectively, in sub- traction. see the sublw and subwf instructions for examples. r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdc c bit 7 bit 0 bit 7-6 irp: register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h - 1ffh) 0 = bank 0, 1 (00h - ffh) bit 6-5 rp1:rp0 : register bank select bits (used for direct addressing) 11 = bank 3 (180h - 1ffh) 10 = bank 2 (100h - 17fh) 11 = bank 1 (80h - ffh) 10 = bank 0 (00h - 7fh) each bank is 128 bytes. bit 4 to : time-out bit 1 = after power-up, clrwdt instruction, or sleep instruction 0 = a wdt time-out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit ( addwf , addlw , sublw , subwf instructions) (for borrow , the polarity is reversed) 1 = a carry-out from the 4th low order bit of the result occurred 0 = no carry-out from the 4th low order bit of the result bit 0 c: carry/borrow bit ( addwf , addlw , sublw , subwf instructions) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note: for borrow , the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 17 pic16f870/871 2.2.2.2 option_reg register the option_reg register is a readable and writable register, which contains various control bits to configure the tmr0 prescaler/wdt postscaler (single assign- able register known also as the prescaler), the external int interrupt, tmr0 and the weak pull-ups on portb. register 2-2: option_reg register (address: 81h,181h) note: to achieve a 1:1 prescaler assignment for the tmr0 register, assign the prescaler to the watchdog timer. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg : interrupt edge select bit 1 = interrupt on rising edge of rb0/int pin 0 = interrupt on falling edge of rb0/int pin bit 5 t0cs : tmr0 clock source select bit 1 = transition on ra4/t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/t0cki pin 0 = increment on low-to-high transition on ra4/t0cki pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps2:ps0 : prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate
pic16f870/871 ds30569b-page 18 ? 2003 microchip technology inc. 2.2.2.3 intcon register the intcon register is a readable and writable regis- ter, which contains various enable and flag bits for the tmr0 register overflow, rb port change and external rb0/int pin interrupts. register 2-3: intcon register (address: 0bh, 8bh, 10bh, 18bh) note: interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user soft- ware should ensure the appropriate inter- rupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie t0ie inte rbie t0if intf rbif bit 7 bit 0 bit 7 gie: global interrupt enable bit 1 = enables all unmasked interrupts 0 = disables all interrupts bit 6 peie : peripheral interrupt enable bit 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts bit 5 t0ie : tmr0 overflow interrupt enable bit 1 = enables the tmr0 interrupt 0 = disables the tmr0 interrupt bit 4 inte : rb0/int external interrupt enable bit 1 = enables the rb0/int external interrupt 0 = disables the rb0/int external interrupt bit 3 rbie : rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 t0if : tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf : rb0/int external interrupt flag bit 1 = the rb0/int external interrupt occurred (must be cleared in software) 0 = the rb0/int external interrupt did not occur bit 0 rbif : rb port change interrupt flag bit 1 = at least one of the rb7:rb4 pins changed state (must be cleared in software) 0 = none of the rb7:rb4 pins have changed state legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 19 pic16f870/871 2.2.2.4 pie1 register the pie1 register contains the individual enable bits for the peripheral interrupts. register 2-4: pie1 register (address: 8ch) note: bit peie (intcon<6>) must be set to enable any peripheral interrupt. r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 pspie (1) : parallel slave port read/write interrupt enable bit 1 = enables the psp read/write interrupt 0 = disables the psp read/write interrupt bit 6 adie : a/d converter interrupt enable bit 1 = enables the a/d converter interrupt 0 = disables the a/d converter interrupt bit 5 rcie : usart receive interrupt enable bit 1 = enables the usart receive interrupt 0 = disables the usart receive interrupt bit 4 txie : usart transmit interrupt enable bit 1 = enables the usart transmit interrupt 0 = disables the usart transmit interrupt bit 3 unimplemented : read as ?0? bit 2 ccp1ie : ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie : tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie : tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt note 1: pspie is reserved on the pic16f870; always maintain this bit clear. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 20 ? 2003 microchip technology inc. 2.2.2.5 pir1 register the pir1 register contains the individual flag bits for the peripheral interrupts. register 2-5: pir1 register (address: 0ch) note: interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user soft- ware should ensure the appropriate inter- rupt bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r-0 r-0 u-0 r/w-0 r/w-0 r/w-0 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 pspif (1) : parallel slave port read/write interrupt flag bit 1 = a read or a write operation has taken place (must be cleared in software) 0 = no read or write has occurred bit 6 adif : a/d converter interrupt flag bit 1 = an a/d conversion completed 0 = the a/d conversion is not complete bit 5 rcif : usart receive interrupt flag bit 1 = the usart receive buffer is full 0 = the usart receive buffer is empty bit 4 txif : usart transmit interrupt flag bit 1 = the usart transmit buffer is empty 0 = the usart transmit buffer is full bit 3 unimplemented : read as ?0? bit 2 ccp1if : ccp1 interrupt flag bit capture mode: 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode: 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode: unused in this mode. bit 1 tmr2if : tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if : tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow note 1: pspif is reserved on the pic16f870; always maintain this bit clear. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 21 pic16f870/871 2.2.2.6 pie2 register the pie2 register contains the individual enable bit for the eeprom write operation interrupt. register 2-6: pie2 register (address: 8dh) u-0 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 ? ? ? eeie ? ? ? ? bit 7 bit 0 bit 7-5 unimplemented: read as '0' bit 4 eeie : eeprom write operation interrupt enable bit 1 = enable ee write interrupt 0 = disable ee write interrupt bit 3-0 unimplemented: read as '0' legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 22 ? 2003 microchip technology inc. 2.2.2.7 pir2 register the pir2 register contains the flag bit for the eeprom write operation interrupt. . register 2-7: pir2 register (address: 0dh) note: interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user soft- ware should ensure the appropriate inter- rupt flag bits are clear prior to enabling an interrupt. u-0 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 ? ? ? eeif ? ? ? ? bit 7 bit 0 bit 7-5 unimplemented: read as '0' bit 4 eeif : eeprom write operation interrupt flag bit 1 = the write operation completed (must be cleared in software) 0 = the write operation is not complete or has not been started bit 3-0 unimplemented: read as '0' legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 23 pic16f870/871 2.2.2.8 pcon register the power control (pcon) register contains flag bits to allow differentiation between a power-on reset (por), a brown-out reset (bor), a watchdog reset (wdt) and an external mclr reset. register 2-8: pcon register (address: 8eh) note: bor is unknown on por. it must be set by the user and checked on subsequent resets to see if bor is clear, indicating a brown-out has occurred. the bor status bit is a don?t care and is not predictable if the brown-out circuit is dis- abled (by clearing the boren bit in the configuration word). u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-1 ? ? ? ? ? ?por bor bit 7 bit 0 bit 7-2 unimplemented: read as '0' bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 24 ? 2003 microchip technology inc. 2.3 pcl and pclath the program counter (pc) is 13-bits wide. the low byte comes from the pcl register, which is a readable and writable register. the upper bits (pc<12:8>) are not readable, but are indirectly writable through the pclath register. on any reset, the upper bits of the pc will be cleared. figure 2-3 shows the two situations for the loading of the pc. the upper example in the fig- ure shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in the fig- ure shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 2-3: loading of pc in different situations 2.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when doing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256-byte block). refer to the application note, ?implementing a table read" (an556). 2.3.2 stack the pic16fxxx family has an 8-level deep x 13-bit wide hardware stack. the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed, or an inter- rupt causes a branch. the stack is poped in the event of a return , retlw or a retfie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 2.4 program memory paging the pic16fxxx architecture is capable of addressing a continuous 8k word block of program memory. the call and goto instructions provide 11 bits of the address, which allows branches within any 2k program memory page. therefore, the 8k words of program memory are broken into four pages. since the pic16f872 has only 2k words of program memory or one page, additional code is not required to ensure that the correct page is selected before a call or goto instruction is executed. the pclath<4:3> bits should always be maintained as zeros. if a return from a call instruction (or interrupt) is executed, the entire 13-bit pc is popped off the stack. manipulation of the pclath is not required for the return instructions. 2.5 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf reg- ister. any instruction using the indf register actually accesses the register pointed to by the file select reg- ister, fsr. reading the indf register itself indirectly (fsr = 0 ) will read 00h. writing to the indf register indirectly results in a no operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit (status<7>), as shown in figure 2-4. a simple program to clear ram locations 20h-2fh using indirect addressing is shown in example 2-1. example 2-1: indirect addressing pc 12 8 7 0 5 pclath<4:0> pclath instruction with alu goto,call opcode <10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl as destination note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call , return , retlw and retfie instruc- tions, or the vectoring to an interrupt address. movlw 0x20 ;initialize pointer movwf fsr ;to ram next clrf indf ;clear indf register incf fsr,f ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next continue : ;yes continue
? 2003 microchip technology inc. ds30569b-page 25 pic16f870/871 figure 2-4: direct/indirect addressing note 1: for register file map detail see figure 2-2. data memory (1) indirect addressing direct addressing bank select location select rp1: rp0 6 0 from opcode irp fsr register 7 0 bank select location select 00 01 10 11 bank 0 bank 1 bank 2 bank 3 ffh 80h 7fh 00h 17fh 100h 1ffh 180h
pic16f870/871 ds30569b-page 26 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 27 pic16f870/871 3.0 data eeprom and flash program memory the data eeprom and flash program memory are readable and writable during normal operation over the entire v dd range. a bulk erase operation may not be issued from user code (which includes removing code protection). the data memory is not directly mapped in the register file space. instead, it is indirectly addressed through the special function registers (sfr). there are six sfrs used to read and write the program and data eeprom memory. these registers are:  eecon1  eecon2  eedata  eedath  eeadr  eeadrh the eeprom data memory allows byte read and write. when interfacing to the data memory block, eedata holds the 8-bit data for read/write and eeadr holds the address of the eeprom location being accessed. the registers eedath and eeadrh are not used for data eeprom access. the pic16f870/871 devices have 64 bytes of data eeprom with an address range from 0h to 3fh. the eeprom data memory is rated for high erase/ write cycles. the write time is controlled by an on-chip timer. the write time will vary with voltage and temper- ature, as well as from chip-to-chip. please refer to the specifications for exact limits. the program memory allows word reads and writes. program memory access allows for checksum calcula- tion and calibration table storage. a byte or word write automatically erases the location and writes the new data (erase before write). writing to program memory will cease operation until the write is complete. the pro- gram memory cannot be accessed during the write, therefore code cannot execute. during the write opera- tion, the oscillator continues to clock the peripherals, and therefore, they continue to operate. interrupt events will be detected and essentially ?queued? until the write is completed. when the write completes, the next instruction in the pipeline is executed and the branch to the interrupt vector address will occur. when interfacing to the program memory block, the eedath:eedata registers form a two-byte word, which holds the 14-bit data for read/write. the eeadrh:eeadr registers form a two-byte word, which holds the 13-bit address of the flash location being accessed. the pic16f870/871 devices have 2k words of program flash with an address range from 0h to 7ffh. the unused upper bits in both the eedath and eedata registers all read as ?0?s. the value written to program memory does not need to be a valid instruction. therefore, up to 14-bit numbers can be stored in memory for use as calibration param- eters, serial numbers, packed 7-bit ascii, etc. execut- ing a program memory location containing data that forms an invalid instruction results in a nop . 3.1 eeadr the address registers can address up to a maximum of 256 bytes of data eeprom or up to a maximum of 8k words of program flash. however, the pic16f870/871 have 64 bytes of data eeprom and 2k words of program flash. when selecting a program address value, the msbyte of the address is written to the eeadrh register and the lsbyte is written to the eeadr register. when selecting a data address value, only the lsbyte of the address is written to the eeadr register. on the pic16f870/871 devices, the upper two bits of the eeadr must always be cleared to prevent inad- vertent access to the wrong location in data eeprom. this also applies to the program memory. the upper five msbits of eeadrh must always be clear during program flash access. 3.2 eecon1 and eecon2 registers the eecon1 register is the control register for config- uring and initiating the access. the eecon2 register is not a physically implemented register, but is used exclusively in the memory write sequence to prevent inadvertent writes. there are many bits used to control the read and write operations to eeprom data and flash program memory. the eepgd bit determines if the access will be a program or data memory access. when clear, any subsequent operations will work on the eeprom data memory. when set, all subsequent operations will operate in the program memory. read operations only use one additional bit, rd, which initiates the read operation from the desired memory location. once this bit is set, the value of the desired memory location will be available in the data registers. this bit cannot be cleared by firmware. it is automati- cally cleared at the end of the read operation. for eeprom data memory reads, the data will be avail- able in the eedata register in the very next instruction cycle after the rd bit is set. for program memory reads, the data will be loaded into the eedath:eedata registers, following the second instruction after the rd bit is set.
pic16f870/871 ds30569b-page 28 ? 2003 microchip technology inc. write operations have two control bits, wr and wren, and two status bits, wrerr and eeif. the wren bit is used to enable or disable the write operation. when wren is clear, the write operation will be disabled. therefore, the wren bit must be set before executing a write operation. the wr bit is used to initiate the write operation. it also is automatically cleared at the end of the write operation. the interrupt flag eeif is used to determine when the memory write completes. this flag must be cleared in software before setting the wr bit. for eeprom data memory, once the wren bit and the wr bit have been set, the desired memory address in eeadr will be erased, followed by a write of the data in eedata. this operation takes place in parallel with the microcontroller continuing to execute normally. when the write is complete, the eeif flag bit will be set. for program memory, once the wren bit and the wr bit have been set, the microcontroller will cease to exe- cute instructions. the desired memory location pointed to by eeadrh:eeadr will be erased. then, the data value in eedath:eedata will be programmed. when complete, the eeif flag bit will be set and the microcontroller will continue to execute code. the wrerr bit is used to indicate when the pic16f870/871 devices have been reset during a write operation. wrerr should be cleared after power-on reset. thereafter, it should be checked on any other reset. the wrerr bit is set when a write operation is interrupted by a mclr reset, or a wdt time-out reset, during normal operation. in these situations, fol- lowing a reset, the user should check the wrerr bit and rewrite the memory location, if set. the contents of the data registers, address registers and eepgd bit are not affected by either mclr reset, or wdt time-out reset, during normal operation. register 3-1: eecon1 register (address: 18ch) r/w-x u-0 u-0 u-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd ? ? ? wrerr wren wr rd bit 7 bit 0 bit 7 eepgd : program/data eeprom select bit 1 = accesses program memory 0 = accesses data memory (this bit cannot be changed while a read or write operation is in progress.) bit 6-4 unimplemented: read as '0' bit 3 wrerr : eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr reset or any wdt reset during normal operation) 0 = the write operation completed bit 2 wren : eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the eeprom bit 1 wr : write control bit 1 = initiates a write cycle. (the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd : read control bit 1 = initiates an eeprom read. (rd is cleared in hardware. the rd bit can only be set (not cleared) in software.) 0 = does not initiate an eeprom read legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 29 pic16f870/871 3.3 reading the eeprom data memory reading eeprom data memory only requires that the desired address to access be written to the eeadr register and clear the eepgd bit. after the rd bit is set, data will be available in the eedata register on the very next instruction cycle. eedata will hold this value until another read operation is initiated or until it is written by firmware. the steps to reading the eeprom data memory are: 1. write the address to eedata. make sure that the address is not larger than the memory size of the pic16f870/871 devices. 2. clear the eepgd bit to point to eeprom data memory. 3. set the rd bit to start the read operation. 4. read the data from the eedata register. example 3-1: eeprom data read 3.4 writing to the eeprom data memory there are many steps in writing to the eeprom data memory. both address and data values must be written to the sfrs. the eepgd bit must be cleared, and the wren bit must be set, to enable writes. the wren bit should be kept clear at all times, except when writing to the eeprom data. the wr bit can only be set if the wren bit was set in a previous operation (i.e., they both cannot be set in the same operation). the wren bit should then be cleared by firmware after the write. clearing the wren bit before the write actually completes will not terminate the write in progress. writes to eeprom data memory must also be pref- aced with a special sequence of instructions that pre- vent inadvertent write operations. this is a sequence of five instructions that must be executed without interrup- tions. the firmware should verify that a write is not in progress before starting another cycle. the steps to write to eeprom data memory are: 1. if step 10 is not implemented, check the wr bit to see if a write is in progress. 2. write the address to eeadr. make sure that the address is not larger than the memory size of the pic16f870/871 devices. 3. write the 8-bit data value to be programmed in the eedata register. 4. clear the eepgd bit to point to eeprom data memory. 5. set the wren bit to enable program operations. 6. disable interrupts (if enabled). 7. execute the special five instruction sequence:  write 55h to eecon2 in two steps (first to w, then to eecon2)  write aah to eecon2 in two steps (first to w, then to eecon2)  set the wr bit 8. enable interrupts (if using interrupts). 9. clear the wren bit to disable program operations. 10. at the completion of the write cycle, the wr bit is cleared and the eeif interrupt flag bit is set. (eeif must be cleared by firmware.) if step 1 is not implemented, then firmware should check for eeif to be set, or wr to clear, to indicate the end of the program cycle. example 3-2: eeprom data write bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addr, w ;write address movwf eeadr ;to read from bsf status, rp0 ;bank 3 bcf eecon1, eepgd ;point to data memory bsf eecon1, rd ;start read operation bcf status, rp0 ;bank 2 movf eedata, w ;w = eedata bsf status, rp1 ; bsf status, rp0 ;bank 3 btfsc eecon1, wr ;wait for goto $-1 ;write to finish bcf status, rp0 ;bank 2 movf addr, w ;address to movwf eeadr ;write to movf value, w ;data to movwf eedata ;write bsf status, rp0 ;bank 3 bcf eecon1, eepgd ;point to data memory bsf eecon1, wren ;enable writes ;only disable interrupts bcf intcon, gie ;if already enabled, ;otherwise discard movlw 0x55 ;write 55h to movwf eecon2 ;eecon2 movlw 0xaa ;write aah to movwf eecon2 ;eecon2 bsf eecon1, wr ;start write operation ;only enable interrupts bsf intcon, gie ;if using interrupts, ;otherwise discard bcf eecon1, wren ;disable writes
pic16f870/871 ds30569b-page 30 ? 2003 microchip technology inc. 3.5 reading the flash program memory reading flash program memory is much like that of eeprom data memory, only two nop instructions must be inserted after the rd bit is set. these two instruction cycles that the nop instructions execute, will be used by the microcontroller to read the data out of program memory and insert the value into the eedath:eedata registers. data will be available following the second nop instruction. eedath and eedata will hold their value until another read operation is initiated, or until they are written by firmware. the steps to reading the flash program memory are: 1. write the address to eeadrh:eeadr. make sure that the address is not larger than the memory size of the pic16f870/871 devices. 2. set the eepgd bit to point to flash program memory. 3. set the rd bit to start the read operation. 4. execute two nop instructions to allow the microcontroller to read out of program memory. 5. read the data from the eedath:eedata registers. example 3-3: flash program read 3.6 writing to the flash program memory writing to flash program memory is unique, in that the microcontroller does not execute instructions while programming is taking place. the oscillator continues to run and all peripherals continue to operate and queue interrupts, if enabled. once the write operation completes (specification d133), the processor begins executing code from where it left off. the other impor- tant difference when writing to flash program mem- ory is that the wrt configuration bit, when clear, prevents any writes to program memory (see table 3-1). just like eeprom data memory, there are many steps in writing to the flash program memory. both address and data values must be written to the sfrs. the eepgd bit must be set, and the wren bit must be set to enable writes. the wren bit should be kept clear at all times, except when writing to the flash program memory. the wr bit can only be set if the wren bit was set in a previous operation (i.e., they both cannot be set in the same operation). the wren bit should then be cleared by firmware after the write. clearing the wren bit before the write actually completes will not terminate the write in progress. writes to program memory must also be prefaced with a special sequence of instructions that prevent inad- vertent write operations. this is a sequence of five instructions that must be executed without interruption for each byte written. these instructions must then be followed by two nop instructions to allow the microcon- troller to setup for the write operation. once the write is complete, the execution of instructions starts with the instruction after the second nop . the steps to write to program memory are: 1. write the address to eeadrh:eeadr. make sure that the address is not larger than the memory size of the pic16f870/871 devices. 2. write the 14-bit data value to be programmed in the eedath:eedata registers. 3. set the eepgd bit to point to flash program memory. 4. set the wren bit to enable program operations. 5. disable interrupts (if enabled). 6. execute the special five instruction sequence:  write 55h to eecon2 in two steps (first to w, then to eecon2)  write aah to eecon2 in two steps (first to w, then to eecon2)  set the wr bit 7. execute two nop instructions to allow the microcontroller to setup for write operation. 8. enable interrupts (if using interrupts). 9. clear the wren bit to disable program operations. bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addrl, w ;write the movwf eeadr ;address bytes movf addrh,w ;for the desired movwf eeadrh ;address to read bsf status, rp0 ;bank 3 bsf eecon1, eepgd ;p oint to program memory bsf eecon1, rd ;start read operation nop ;required two nops nop ; bcf status, rp0 ;bank 2 movf eedata, w ;datal = eedata movwf datal ; movf eedath,w ;datah = eedath movwf datah ;
? 2003 microchip technology inc. ds30569b-page 31 pic16f870/871 at the completion of the write cycle, the wr bit is cleared and the eeif interrupt flag bit is set. (eeif must be cleared by firmware.) since the microcontroller does not execute instructions during the write cycle, the firmware does not necessarily have to check either eeif, or wr, to determine if the write had finished. example 3-4: flash program write 3.7 write verify the pic16f870/871 devices do not automatically ver- ify the value written during a write operation. depend- ing on the application, good programming practice may dictate that the value written to memory be verified against the original value. this should be used in appli- cations where excessive writes can stress bits near the specified endurance limits. 3.8 protection against spurious writes there are conditions when the device may not want to write to the eeprom data memory or flash program memory. to protect against these spurious write condi- tions, various mechanisms have been built into the pic16f870/871 devices. on power-up, the wren bit is cleared and the power-up timer (if enabled) prevents writes. the write initiate sequence and the wren bit together, help prevent any accidental writes during brown-out, power glitches, or firmware malfunction. 3.9 operation while code protected the pic16f870/871 devices have two code protect mechanisms, one bit for eeprom data memory and two bits for flash program memory. data can be read and written to the eeprom data memory, regardless of the state of the code protection bit, cpd. when code protection is enabled and cpd cleared, external access via icsp is disabled, regardless of the state of the program memory code protect bits. this prevents the contents of eeprom data memory from being read out of the device. the state of the program memory code protect bits, cp0 and cp1, do not affect the execution of instruc- tions out of program memory. the pic16f870/871 devices can always read the values in program mem- ory, regardless of the state of the code protect bits. however, the state of the code protect bits and the wrt bit will have different effects on writing to program memory. table 4-1 shows the effect of the code protect bits and the wrt bit on program memory. once code protection has been enabled for either eeprom data memory or flash program memory, only a full erase of the entire device will disable code protection. bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addrl, w ;write address movwf eeadr ;of desired movf addrh, w ;program memory movwf eeadrh ;location movf valuel, w ;write value to movwf eedata ;program at movf valueh, w ;desired memory movwf eedath ;location bsf status, rp0 ;bank 3 bsf eecon1, eepgd ;point to p rogram memor y bsf eecon1, wren ;enable writes ;only disable interrupt s bcf intcon, gie ;if already enabled, ;otherwise discard movlw 0x55 ;write 55h to movwf eecon2 ;eecon2 movlw 0xaa ;write aah to movwf eecon2 ;eecon2 bsf eecon1, wr ;start write operation nop ;two nops to allow micr o nop ;to setup for write ;only enable interrupts bsf intcon, gie ;if using interrupts, ;otherwise discard bcf eecon1, wren ;disable writes
pic16f870/871 ds30569b-page 32 ? 2003 microchip technology inc. 3.10 flash program memory write protection the configuration word contains a bit that write protects the flash program memory, called wrt. this bit can only be accessed when programming the pic16f870/871 devices via icsp. once write protec- tion is enabled, only an erase of the entire device will disable it. when enabled, write protection prevents any writes to flash program memory. write protection does not affect program memory reads. table 3-1: read/write state of internal flash program memory table 3-2: registers associated with data eeprom/program flash configuration bits memory location internal read internal write icsp read icsp write cp1 cp0 wrt 00x all program memory yes no no no 010 unprotected areas yes no yes no 010 protected areas yes no no no 011 unprotected areas yes yes yes no 011 protected areas yes no no no 100 unprotected areas yes no yes no 100 protected areas yes no no no 101 unprotected areas yes yes yes no 101 protected areas yes no no no 110 all program memory yes no yes yes 111 all program memory yes yes yes yes address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 10dh eeadr eeprom address register, low byte xxxx xxxx uuuu uuuu 10fh eeadrh ? ? ? eeprom address, high byte xxxx xxxx uuuu uuuu 10ch eedata eeprom data register, low byte xxxx xxxx uuuu uuuu 10eh eedath ? ? eeprom data register, high byte xxxx xxxx uuuu uuuu 18ch eecon1 eepgd ? ? ? wrerr wren wr rd x--- x000 x--- u000 18dh eecon2 eeprom control register2 (not a physical register) ? ? legend: x = unknown, u = unchanged, r = reserved, - = unimplemented, read as '0'. shaded cells are not used during flash/eeprom access. note 1: these bits are reserved; always maintain these bits clear.
? 2003 microchip technology inc. ds30569b-page 33 pic16f870/871 4.0 i/o ports some pins for these i/o ports are multiplexed with an alternate function for the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. additional information on i/o ports may be found in the picmicro? mid-range mcu family reference manual (ds33023). 4.1 porta and the trisa register porta is a 6-bit wide bi-directional port. the corre- sponding data direction register is trisa. setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a hi-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, the value is modified and then written to the port data latch. pin ra4 is multiplexed with the timer0 module clock input to become the ra4/t0cki pin. the ra4/t0cki pin is a schmitt trigger input and an open drain output. all other porta pins have ttl input levels and full cmos output drivers. other porta pins are multiplexed with analog inputs and analog v ref input. the operation of each pin is selected by clearing/setting the control bits in the adcon1 register (a/d control register 1). the trisa register controls the direction of the ra pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. example 4-1: initializing porta figure 4-1: block diagram of ra3:ra0 and ra5 pins figure 4-2: block diagram of ra4/t0cki pin note: on a power-on reset, these pins are configured as analog inputs and read as '0'. bcf status, rp0 ; bcf status, rp1 ;bank0 clrf porta ;initialize porta by ;clearing output ;data latches bsf status, rp0 ;select bank 1 movlw 0x06 ;configure all pins movwf adcon1 ;as digital inputs movlw 0xcf ;value used to ;initialize data ;direction movwf trisa ;set ra<3:0> as ;inputs ;ra<5:4> as outputs ;trisa<7:6> are ;always read as '0'. data bus q d q ck q d q ck qd en p n wr port wr tris data latch tris latch rd tris rd port v ss v dd i/o pin (1) note 1: i/o pins have protection diodes to v dd and v ss . analog input mode ttl input buffer to a/d converter data bus wr port wr tris rd port data latch tris latch rd tris schmitt trigger input buffer n v ss i/o pin (1) tmr0 clock input q d q ck q d q ck en qd en note 1: i/o pin has protection diodes to v ss only.
pic16f870/871 ds30569b-page 34 ? 2003 microchip technology inc. table 4-1: porta functions table 4-2: summary of registers associated with porta name bit# buffer function ra0/an0 bit0 ttl input/output or analog input. ra1/an1 bit1 ttl input/output or analog input. ra2/an2 bit2 ttl input/output or analog input. ra3/an3/v ref bit3 ttl input/output or analog input or v ref. ra4/t0cki bit4 st input/output or external clock input for timer0. output is open drain type. ra5/an4 bit5 ttl input/output or analog input. legend: ttl = ttl input, st = schmitt trigger input address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 05h porta ? ? ra5 ra4 ra3 ra2 ra1 ra0 --0x 0000 --0u 0000 85h trisa ? ? porta data direction register --11 1111 --11 1111 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 --0- 0000 --0- 0000 legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. shaded cells are not used by porta.
? 2003 microchip technology inc. ds30569b-page 35 pic16f870/871 4.2 portb and the trisb register portb is an 8-bit wide, bi-directional port. the corre- sponding data direction register is trisb. setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a hi-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). three pins of portb are multiplexed with the low voltage programming function: rb3/pgm, rb6/pgc and rb7/pgd. the alternate functions of these pins are described in the special features section. each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is per- formed by clearing bit rbpu (option_reg<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. figure 4-3: block diagram of rb3:rb0 pins four of portb?s pins, rb7:rb4, have an interrupt-on- change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb7:rb4 pin configured as an output is excluded from the interrupt- on-change comparison). the input pins (of rb7:rb4) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb7:rb4 are or?ed together to generate the rb port change interrupt with flag bit rbif (intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb. this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. this interrupt on mismatch feature, together with soft- ware configurable pull-ups on these four pins, allow easy interface to a keypad and make it possible for wake-up on key-depression. refer to the embedded control handbook, ?implementing wake-up on key stroke? (an552). rb0/int is an external interrupt input pin and is configured using the intedg bit (option_reg<6>). rb0/int is discussed in detail in section 11.10.1. figure 4-4: block diagram of rb7:rb4 pins data latch rbpu (2) p v dd q d ck q d ck qd en data bus wr port wr tris rd tris rd port weak pull-up rd port rb0/int i/o pin (1) ttl input buffer schmitt trigger buffer tris latch note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (option_reg<7>). rb3/pgm data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr port wr tris set rbif tris latch rd tris rd port rb7:rb4 pins weak pull-up rd port latch ttl input buffer st buffer rb7:rb6 in serial programming mode q3 q1 note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (option_reg<7>).
pic16f870/871 ds30569b-page 36 ? 2003 microchip technology inc. table 4-3: portb functions table 4-4: summary of registers associated with portb name bit# buffer function rb0/int bit0 ttl/st (1) input/output pin or external interrupt input. internal software programmable weak pull-up. rb1 bit1 ttl input/output pin. internal software programmable weak pull-up. rb2 bit2 ttl input/output pin. internal software programmable weak pull-up. rb3/pgm bit3 ttl/st (1) input/output pin or programming pin in lvp mode. internal software programmable weak pull-up. rb4 bit4 ttl input/output pin (with interrupt-on-change). internal software programmable weak pull-up. rb5 bit5 ttl input/output pin (with interrupt-on-change). internal software programmable weak pull-up. rb6/pgc bit6 ttl/st (2) input/output pin (with interrupt-on-change) or in-circuit debugger pin. internal software programmable weak pull-up. serial programming clock. rb7/pgd bit7 ttl/st (2) input/output pin (with interrupt-on-change) or in-circuit debugger pin. internal software programmable weak pull-up. serial programming data. legend: ttl = ttl input, st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt or lvp mode. 2: this buffer is a schmitt trigger input when used in serial programming mode. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 06h, 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 86h, 186h trisb portb data direction register 1111 1111 1111 1111 81h, 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged. shaded cells are not used by portb.
? 2003 microchip technology inc. ds30569b-page 37 pic16f870/871 4.3 portc and the trisc register portc is an 8-bit wide, bi-directional port. the corre- sponding data direction register is trisc. setting a trisc bit (= 1 ) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a hi-impedance mode). clearing a trisc bit (= 0 ) will make the corresponding portc pin an output (i.e., put the contents of the output latch on the selected pin). portc is multiplexed with several peripheral functions (table 4-5). portc pins have schmitt trigger input buffers. when enabling peripheral functions, care should be taken in defining tris bits for each portc pin. some peripherals override the tris bit to make a pin an out- put, while other peripherals override the tris bit to make a pin an input. since the tris bit override is in effect while the peripheral is enabled, read-modify- write instructions ( bsf, bcf, xorwf ) with trisc as the destination should be avoided. the user should refer to the corresponding peripheral section for the correct tris bit settings. figure 4-5: portc block diagram (peripheral output override) table 4-5: portc functions table 4-6: summary of registers associated with portc port/peripheral select (2) data bus wr port wr tris rd data latch tris latch rd tris schmitt trigger q d q ck qd en peripheral data out 0 1 q d q ck p n v dd vss port peripheral oe (3) peripheral input i/o pin (1) note 1: i/o pins have diode protection to v dd and v ss . 2: port/peripheral select signal selects between port data and peripheral output. 3: peripheral oe (output enable) is only activated if peripheral select is active. name bit# buffer type function rc0/t1oso/t1cki bit0 st input/output port pin or timer1 oscillator output/timer1 clock input. rc1/t1osi bit1 st input/output port pin or timer1 oscillator input. rc2/ccp1 bit2 st input/output port pin or capture1 input/compare1 output/ pwm1 output. rc3 bit3 st input/output port pin. rc4 bit4 st input/output port pin. rc5 bit5 st input/output port pin. rc6/tx/ck bit6 st input/output port pin or usart asynchronous transmit or synchronous clock. rc7/rx/dt bit7 st input/output port pin or usart asynchronous receive or synchronous data. legend: st = schmitt trigger input address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 07h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu 87h trisc portc data direction register 1111 1111 1111 1111 legend: x = unknown, u = unchanged
pic16f870/871 ds30569b-page 38 ? 2003 microchip technology inc. 4.4 portd and trisd registers this section is not applicable to the pic16f870. portd is an 8-bit port with schmitt trigger input buff- ers. each pin is individually configurable as an input or output. portd can be configured as an 8-bit wide micropro- cessor port (parallel slave port) by setting control bit pspmode (trise<4>). in this mode, the input buffers are ttl. figure 4-6: portd block diagram (in i/o port mode) table 4-7: portd functions table 4-8: summary of registers associated with portd data bus wr port wr tris rd port data latch tris latch rd tris schmitt trigger input buffer i/o pin (1) note 1: i/o pins have protection diodes to v dd and v ss . q d ck q d ck en qd en name bit# buffer type function rd0/psp0 bit0 st/ttl (1) input/output port pin or parallel slave port bit0. rd1/psp1 bit1 st/ttl (1) input/output port pin or parallel slave port bit1. rd2/psp2 bit2 st/ttl (1) input/output port pin or parallel slave port bit2. rd3/psp3 bit3 st/ttl (1) input/output port pin or parallel slave port bit3. rd4/psp4 bit4 st/ttl (1) input/output port pin or parallel slave port bit4. rd5/psp5 bit5 st/ttl (1) input/output port pin or parallel slave port bit5. rd6/psp6 bit6 st/ttl (1) input/output port pin or parallel slave port bit6. rd7/psp7 bit7 st/ttl (1) input/output port pin or parallel slave port bit7. legend: st = schmitt trigger input, ttl = ttl input note 1: input buffers are schmitt triggers when in i/o mode and ttl buffers when in parallel slave port mode. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 08h portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx uuuu uuuu 88h trisd portd data direction register 1111 1111 1111 1111 89h trise ibf obf ibov pspmode ? porte data direction bits 0000 -111 0000 -111 legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded cells are not used by portd.
? 2003 microchip technology inc. ds30569b-page 39 pic16f870/871 4.5 porte and trise register this section is not applicable to the pic16f870. porte has three pins, re0/rd /an5, re1/wr /an6 and re2/cs /an7, which are individually configurable as inputs or outputs. these pins have schmitt trigger input buffers. i/o porte becomes control inputs for the micropro- cessor port when bit pspmode (trise<4>) is set. in this mode, the user must make sure that the trise<2:0> bits are set (pins are configured as digital inputs). ensure adcon1 is configured for digital i/o. in this mode, the input buffers are ttl. register 4-1 shows the trise register, which also controls the parallel slave port operation. porte pins are multiplexed with analog inputs. when selected as an analog input, these pins will read as '0's. trise controls the direction of the re pins, even when they are being used as analog inputs. the user must make sure to keep the pins configured as inputs when using them as analog inputs. figure 4-7: porte block diagram (in i/o port mode) note: on a power-on reset, these pins are configured as analog inputs. data bus wr port wr tris rd port data latch tris latch rd tris schmitt trigger input buffer q d ck q d ck qd en i/o pin (1) note 1: i/o pins have protection diodes to v dd and v ss .
pic16f870/871 ds30569b-page 40 ? 2003 microchip technology inc. register 4-1: trise register (address: 89h) r-0 r-0 r/w-0 r/w-0 u-0 r/w-1 r/w-1 r/w-1 ibf obf ibov pspmode ? bit2 bit1 bit0 bit 7 bit 0 bit 7 parallel slave port status/control bits ibf: input buffer full status bit 1 = a word has been received and is waiting to be read by the cpu 0 = no word has been received bit 6 obf : output buffer full status bit 1 = the output buffer still holds a previously written word 0 = the output buffer has been read bit 5 ibov : input buffer overflow detect bit (in microprocessor mode) 1 = a write occurred when a previously input word has not been read (must be cleared in software) 0 = no overflow occurred bit 4 pspmode : parallel slave port mode select bit 1 = parallel slave port mode 0 = general purpose i/o mode bit 3 unimplemented : read as '0' porte data direction bits bit 2 bit2 : direction control bit for pin re2/cs /an7 1 = input 0 = output bit 1 bit1 : direction control bit for pin re1/wr /an6 1 = input 0 = output bit 0 bit0 : direction control bit for pin re0/rd /an5 1 = input 0 = output legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 41 pic16f870/871 table 4-9: porte functions table 4-10: summary of registers associated with porte name bit# buffer type function re0/rd /an5 bit0 st/ttl (1) input/output port pin or read control input in parallel slave port mode or analog input: rd 1 = not a read operation 0 = read operation. reads portd register (if chip selected.) re1/wr /an6 bit1 st/ttl (1) input/output port pin or write control input in parallel slave port mode or analog input: wr 1 = not a write operation 0 = write operation. writes portd register (if chip selected). re2/cs /an7 bit2 st/ttl (1) input/output port pin or chip select control input in parallel slave port mode or analog input: cs 1 = device is not selected 0 = device is selected legend: st = schmitt trigger input, ttl = ttl input note 1: input buffers are schmitt triggers when in i/o mode and ttl buffers when in parallel slave port mode. addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 09h porte ? ? ? ? ?re2re1re0 ---- -xxx ---- -uuu 89h trise ibf obf ibov pspmode ? porte data direction bits 0000 -111 0000 -111 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 --0- 0000 --0- 0000 legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded cells are not used by porte.
pic16f870/871 ds30569b-page 42 ? 2003 microchip technology inc. 4.6 parallel slave port the parallel slave port is not implemented on the pic16f870. portd operates as an 8-bit wide parallel slave port or microprocessor port when control bit pspmode (trise<4>) is set. in slave mode, it is asynchronously readable and writable by the external world through rd control input pin re0/rd and wr control input pin re1/wr . it can directly interface to an 8-bit microprocessor data bus. the external microprocessor can read or write the portd latch as an 8-bit latch. setting bit pspmode enables port pin re0/rd to be the rd input, re1/wr to be the wr input and re2/cs to be the cs (chip select) input. for this functionality, the corresponding data direction bits of the trise register (trise<2:0>) must be configured as inputs (set). the a/d port config- uration bits pcfg3:pcfg0 (adcon1<3:0>) must be set to configure pins re2:re0 as digital i/o. there are actually two 8-bit latches. one for data out- put and one for data input. the user writes 8-bit data to the portd data latch and reads data from the port pin latch (note that they have the same address). in this mode, the trisd register is ignored, since the microprocessor is controlling the direction of data flow. a write to the psp occurs when both the cs and wr lines are first detected low. when either the cs or wr lines become high (level triggered), the input buffer full (ibf) status flag bit (trise<7>) is set on the q4 clock cycle, following the next q2 cycle, to signal the write is complete (figure 4-9). the interrupt flag bit, pspif (pir1<7>), is also set on the same q4 clock cycle. ibf can only be cleared by reading the portd input latch. the input buffer overflow (ibov) status flag bit (trise<5>) is set if a second write to the psp is attempted when the previous byte has not been read out of the buffer. a read from the psp occurs when both the cs and rd lines are first detected low. the output buffer full (obf) status flag bit (trise<6>) is cleared immedi- ately (figure 4-10), indicating that the portd latch is waiting to be read by the external bus. when either the cs or rd pin becomes high (level triggered), the inter- rupt flag bit pspif is set on the q4 clock cycle, follow- ing the next q2 cycle, indicating that the read is complete. obf remains low until data is written to portd by the user firmware. when not in psp mode, the ibf and obf bits are held clear. however, if flag bit ibov was previously set, it must be cleared in firmware. an interrupt is generated and latched into flag bit pspif when a read or write operation is completed. pspif must be cleared by the user in firmware and the interrupt can be disabled by clearing the interrupt enable bit pspie (pie1<7>). figure 4-8: portd and porte block diagram (parallel slave port) data bus wr port rd rdx q d ck en qd en port pin one bit of portd set interrupt flag pspif (pir1<7>) read chip select write rd cs wr note: i/o pin has protection diodes to v dd and v ss . ttl ttl ttl ttl
? 2003 microchip technology inc. ds30569b-page 43 pic16f870/871 figure 4-9: parallel slave port write waveforms figure 4-10: parallel slave port read waveforms table 4-11: registers associated with parallel slave port address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 08h portd port data latch when written: port pins when read xxxx xxxx uuuu uuuu 09h porte ? ? ? ? ?re2re1re0 ---- -xxx ---- -uuu 89h trise ibf obf ibov pspmode ? porte data direction bits 0000 -111 0000 -111 0ch pir1 pspif adif rcif txif ? ccp1if tmr2if tmr1if 0000 0000 0000 0000 8ch pie1 pspie adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 --0- 0000 --0- 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used by the parallel slave port. q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr rd ibf obf pspif portd<7:0> q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr ibf pspif rd obf portd<7:0>
pic16f870/871 ds30569b-page 44 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 45 pic16f870/871 5.0 timer0 module the timer0 module timer/counter has the following features:  8-bit timer/counter  readable and writable  8-bit software programmable prescaler  internal or external clock select  interrupt on overflow from ffh to 00h  edge select for external clock figure 5-1 is a block diagram of the timer0 module and the prescaler shared with the wdt. additional information on the timer0 module is avail- able in the picmicro? mid-range mcu family reference manual (ds33023). timer mode is selected by clearing bit t0cs (option_reg<5>). in timer mode, the timer0 mod- ule will increment every instruction cycle (without pres- caler). if the tmr0 register is written, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting bit t0cs (option_reg<5>). in counter mode, timer0 will increment either on every rising, or falling edge of pin ra4/t0cki. the incrementing edge is determined by the timer0 source edge select bit, t0se (option_reg<4>). clearing bit t0se selects the ris- ing edge. restrictions on the external clock input are discussed in detail in section 5.2. the prescaler is mutually exclusively shared between the timer0 module and the watchdog timer. the pres- caler is not readable or writable. section 5.3 details the operation of the prescaler. 5.1 timer0 interrupt the tmr0 interrupt is generated when the tmr0 reg- ister overflows from ffh to 00h. this overflow sets bit t0if (intcon<2>). the interrupt can be masked by clearing bit t0ie (intcon<5>). bit t0if must be cleared in software by the timer0 module interrupt ser- vice routine before re-enabling this interrupt. the tmr0 interrupt cannot awaken the processor from sleep, since the timer is shut-off during sleep. figure 5-1: block diagram of the timer0/wdt prescaler ra4/t0cki t0se pin m u x clko (= f osc /4) sync 2 cycles tmr0 reg 8-bit prescaler 8 - to - 1mux m u x m u x watchdog timer psa 0 1 0 1 wdt time-out ps2:ps0 8 note: t0cs, t0se, psa, ps2:ps0 are (option_reg<5:0>). psa wdt enable bit m u x 0 1 0 1 data bus set flag bit t0if on overflow 8 psa t0cs prescaler
pic16f870/871 ds30569b-page 46 ? 2003 microchip technology inc. 5.2 using timer0 with an external clock when no prescaler is used, the external clock input is the same as the prescaler output. the synchronization of t0cki with the internal phase clocks is accom- plished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, it is necessary for t0cki to be high for at least 2 t osc (and a small rc delay of 20 ns) and low for at least 2 t osc (and a small rc delay of 20 ns). refer to the electrical specification of the desired device. 5.3 prescaler there is only one prescaler available, which is mutually exclusively shared between the timer0 module and the watchdog timer. a prescaler assignment for the timer0 module means that there is no prescaler for the watchdog timer, and vice-versa. this prescaler is not readable or writable (see figure 5-1). the psa and ps2:ps0 bits (option_reg<3:0>) determine the prescaler assignment and prescale ratio. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf1 , movwf1 , bsf1,x ....etc.) will clear the prescaler. when assigned to wdt, a clrwdt instruction will clear the prescaler along with the watchdog timer. the prescaler is not readable or writable. register 5-1: option_reg register note: writing to tmr0 when the prescaler is assigned to timer0, will clear the prescaler count, but will not change the prescaler assignment. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu bit 6 intedg bit 5 t0cs : tmr0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps2:ps0 : prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: to avoid an unintended device reset, the instruction sequence shown in the picmicro? mid-range mcu family reference manual (ds33023) must be executed when changing the prescaler assignment from timer0 to the wdt. this sequence must be followed even if the wdt is disabled. 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate
? 2003 microchip technology inc. ds30569b-page 47 pic16f870/871 table 5-1: registers associated with timer0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 01h,101h tmr0 timer0 module?s register xxxx xxxx uuuu uuuu 0bh,8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 81h,181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. shaded cells are not used by timer0.
pic16f870/871 ds30569b-page 48 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 49 pic16f870/871 6.0 timer1 module the timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (tmr1h and tmr1l), which are readable and writable. the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the tmr1 interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing tmr1 interrupt enable bit, tmr1ie (pie1<0>). timer1 can operate in one of two modes: as a timer as a counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). in timer mode, timer1 increments every instruction cycle. in counter mode, it increments on every rising edge of the external clock input. timer1 can be enabled/disabled by setting/clearing control bit, tmr1on (t1con<0>). timer1 also has an internal ?reset input?. this reset can be generated by either of the two ccp modules (section 8.0). register 6-1 shows the timer1 control register. when the timer1 oscillator is enabled (t1oscen is set), the rc1/t1osi and rc0/t1oso/t1cki pins become inputs. that is, the trisc<1:0> value is ignored, and these pins read as ?0?. additional information on timer modules is available in the picmicro? mid-range mcu family reference manual (ds33023). register 6-1: t1con: timer1 co ntrol register (address: 10h) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7-6 unimplemented: read as '0' bit 5-4 t1ckps1:t1ckps0 : timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen : timer1 oscillator enable control bit 1 = oscillator is enabled 0 = oscillator is shut-off (the oscillator inverter is turned off to eliminate power drain) bit 2 t1sync : timer1 external clock input synchronization control bit when tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock when tmr1cs = 0 . bit 1 tmr1cs : timer1 clock source select bit 1 = external clock from pin rc0/t1oso/t1cki (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on : timer1 on bit 1 = enables timer1 0 = stops timer1 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 50 ? 2003 microchip technology inc. 6.1 timer1 operation in timer mode timer mode is selected by clearing the tmr1cs (t1con<1>) bit. in this mode, the input clock to the timer is f osc /4. the synchronize control bit, t1sync (t1con<2>), has no effect, since the internal clock is always in sync. 6.2 timer1 counter operation timer1 may operate in either a synchronous, or an asynchronous mode, depending on the setting of the tmr1cs bit. when timer1 is being incremented via an external source, increments occur on a rising edge. after timer1 is enabled in counter mode, the module must first have a falling edge before the counter begins to increment. figure 6-1: timer1 incrementing edge 6.3 timer1 operation in synchronized counter mode counter mode is selected by setting bit tmr1cs. in this mode, the timer increments on every rising edge of clock input on pin rc1/t1osi, when bit t1oscen is set, or on pin rc0/t1oso/t1cki, when bit t1oscen is cleared. if t1sync is cleared, then the external clock input is synchronized with internal phase clocks. the synchro- nization is done after the prescaler stage. the prescaler stage is an asynchronous ripple counter. in this configuration, during sleep mode, timer1 will not increment even if the external clock is present, since the synchronization circuit is shut-off. the prescaler, however, will continue to increment. figure 6-2: timer1 block diagram t1cki (default high) t1cki (default low) note: arrows indicate counter increments. tmr1h tmr1l t1osc t1sync tmr1cs t1ckps1:t1ckps0 q clock t1oscen enable oscillator (1) f osc /4 internal clock tmr1on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 rc0/t1oso/t1cki rc1/t1osi note 1: when the t1oscen bit is cleared, the inverter is turned off. this eliminates power drain. set flag bit tmr1if on overflow tmr1
? 2003 microchip technology inc. ds30569b-page 51 pic16f870/871 6.4 timer1 operation in asynchronous counter mode if control bit t1sync (t1con<2>) is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt-on-overflow, which will wake-up the processor. however, special precautions in software are needed to read/write the timer (section 6.4.1). in asynchronous counter mode, timer1 cannot be used as a time base for capture or compare operations. 6.4.1 reading and writing timer1 in asynchronous counter mode reading tmr1h or tmr1l while the timer is running from an external asynchronous clock, will ensure a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write conten- tion may occur by writing to the timer registers, while the register is incrementing. this may produce an unpredictable value in the timer register. reading the 16-bit value requires some care. examples 12-2 and 12-3 in the picmicro? mid-range mcu family reference manual (ds33023) show how to read and write timer1 when it is running in asynchronous mode. 6.5 timer1 oscillator a crystal oscillator circuit is built-in between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting control bit, t1oscen (t1con<3>). the oscil- lator is a low power oscillator, rated up to 200 khz. it will continue to run during sleep. it is primarily intended for use with a 32 khz crystal. table 6-1 shows the capacitor selection for the timer1 oscillator. the timer1 oscillator is identical to the lp oscillator. the user must provide a software time delay to ensure proper oscillator start-up. table 6-1: capacitor selection for the timer1 oscillator 6.6 resetting timer1 using a ccp trigger output if the ccp1 module is configured in compare mode to generate a ?special event trigger? (ccp1m3:ccp1m0 = 1011 ), this signal will reset timer1. timer1 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger from ccp1, the write will take precedence. in this mode of operation, the ccprh:ccprl register pair effectively becomes the period register for timer1. osc type freq. c1 c2 lp 32 khz 33 pf 33 pf 100 khz 15 pf 15 pf 200 khz 15 pf 15 pf these values are for design guidance only. crystals tested: 32.768 khz epson c-001r32.768k-a 20 ppm 100 khz epson c-2 100.00 kc-p 20 ppm 200 khz std xtl 200.000 khz 20 ppm note 1: higher capacitance increases the stability of oscillator, but also increases the start-up time. 2: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. note: the special event triggers from the ccp1 module will not set interrupt flag bit tmr1if (pir1<0>).
pic16f870/871 ds30569b-page 52 ? 2003 microchip technology inc. 6.7 resetting of timer1 register pair (tmr1h, tmr1l) tmr1h and tmr1l registers are not reset to 00h on a por, or any other reset, except by the ccp1 special event trigger. t1con register is reset to 00h on a power-on reset, or a brown-out reset, which shuts off the timer and leaves a 1:1 prescale. in all other resets, the register is unaffected. 6.8 timer1 prescaler the prescaler counter is cleared on writes to the tmr1h or tmr1l registers. table 6-2: registers associated with timer1 as a timer/counter address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cell s are not used by the timer1 module. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear.
? 2003 microchip technology inc. ds30569b-page 53 pic16f870/871 7.0 timer2 module timer2 is an 8-bit timer with a prescaler and a postscaler. it can be used as the pwm time base for the pwm mode of the ccp module(s). the tmr2 register is readable and writable, and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4, or 1:16, selected by control bits t2ckps1:t2ckps0 (t2con<1:0>). the timer2 module has an 8-bit period register, pr2. timer2 increments from 00h until it matches pr2 and then resets to 00h on the next increment cycle. pr2 is a readable and writable register. the pr2 register is initialized to ffh upon reset. the match output of tmr2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a tmr2 interrupt (latched in flag bit tmr2if (pir1<1>)). timer2 can be shut-off by clearing control bit, tmr2on (t2con<2>), to minimize power consumption. register 7-1 shows the timer2 control register. additional information on timer modules is available in the picmicro? mid-range mcu family reference manual (ds33023). figure 7-1: timer2 block diagram register 7-1: t2con: timer2 co ntrol register (address 12h) comparator tmr2 sets flag tmr2 reg output (1) reset postscaler prescaler pr2 reg 2 f osc /4 1:1 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if note 1: tmr2 register output can be software selected by the ssp module as a baud clock. to t2outps3: t2outps0 t2ckps1: t2ckps0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as '0' bit 6-3 toutps3:toutps0 : timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale 0010 = 1:3 postscale    1111 = 1:16 postscale bit 2 tmr2on : timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps1:t2ckps0 : timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 54 ? 2003 microchip technology inc. 7.1 timer2 prescaler and postscaler the prescaler and postscaler counters are cleared when any of the following occurs:  a write to the tmr2 register  a write to the t2con register  any device reset (por, mclr reset, wdt reset, or bor) tmr2 is not cleared when t2con is written. 7.2 output of tmr2 the output of tmr2 (before the postscaler) is fed to the ssp module, which optionally uses it to generate shift clock. table 7-1: registers associated with timer2 as a timer/counter address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 11h tmr2 timer2 module?s register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used by the timer2 module. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear.
? 2003 microchip technology inc. ds30569b-page 55 pic16f870/871 8.0 capture/compare/pwm modules each capture/compare/pwm (ccp) module contains a 16-bit register which can operate as a:  16-bit capture register  16-bit compare register  pwm master/slave duty cycle register table 8-1 shows the resources and interactions of the ccp module. in the following sections, the operation of a ccp module is described. 8.1 ccp1 module capture/compare/pwm register1 (ccpr1) is com- prised of two 8-bit registers: ccpr1l (low byte) and ccpr1h (high byte). the ccp1con register controls the operation of ccp1. the special event trigger is generated by a compare match and will reset timer1 and start an a/d conversion (if the a/d module is enabled). additional information on ccp modules is available in the picmicro? mid-range mcu family reference manual (ds33023) and in application note an594, ?using the ccp modules? (ds00594). table 8-1: ccp mode - timer resources required register 8-1: ccp1con register register (address: 17h/1dh) ccp mode timer resource capture compare pwm timer1 timer1 timer2 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 unimplemented: read as '0' bit 5-4 ccp1x:ccp1y : pwm least significant bits capture mode : unused compare mode: unused pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccpr1l. bit 3-0 ccp1m3:ccp1m0 : ccp1 mode select bits 0000 = capture/compare/pwm disabled (resets ccp1 module) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit is set) 1001 = compare mode, clear output on match (ccp1if bit is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp1if bit is set, ccp1 pin is unaffected); ccp1resets tmr1, and starts an a/d conversion (if a/d module is enabled) 11xx = pwm mode legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 56 ? 2003 microchip technology inc. 8.2 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on pin rc2/ccp1. an event is defined as one of the following:  every falling edge  every rising edge  every 4th rising edge  every 16th rising edge the type of event is configured by control bits ccp1m3:ccp1m0 (ccp1con<3:0>). when a cap- ture is made, the interrupt request flag bit ccp1if (pir1<2>) is set. the interrupt flag must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value is overwritten by the new value. 8.2.1 ccp pin configuration in capture mode, the rc2/ccp1 pin should be configured as an input by setting the trisc<2> bit. figure 8-1: capture mode operation block diagram 8.2.2 timer1 mode selection timer1 must be running in timer mode, or synchro- nized counter mode, for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 8.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccp1ie (pie1<2>) clear to avoid false interrupts and should clear the flag bit, ccp1if, following any such change in operating mode. 8.2.4 ccp prescaler there are four prescaler settings, specified by bits ccp1m3:ccp1m0. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared, therefore, the first capture may be from a non-zero prescaler. example 8-1 shows the recom- mended method for switching between capture pres- calers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 8-1: changing between capture prescalers note: if the rc2/ccp1 pin is configured as an output, a write to the port can cause a capture condition. ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1<2>) capture enable qs ccp1con<3:0> rc2/ccp1 prescaler 1, 4, 16 and edge detect pin clrf ccp1con ; turn ccp module off movlw new_capt_ps ; load the w reg with ; the new prescaler ; move value and ccp on movwf ccp1con ; load ccp1con with this ; value
? 2003 microchip technology inc. ds30569b-page 57 pic16f870/871 8.3 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the rc2/ccp1 pin is:  driven high driven low  remains unchanged the action on the pin is based on the value of control bits, ccp1m3:ccp1m0 (ccp1con<3:0>). at the same time, interrupt flag bit ccp1if is set. figure 8-2: compare mode operation block diagram 8.3.1 ccp pin configuration the user must configure the rc2/ccp1 pin as an output by clearing the trisc<2> bit. 8.3.2 timer1 mode selection timer1 must be running in timer mode, or synchro- nized counter mode, if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 8.3.3 software interrupt mode when generate software interrupt mode is chosen, the ccp1 pin is not affected. the ccpif bit is set, causing a ccp interrupt (if enabled). 8.3.4 special event trigger in this mode, an internal hardware trigger is generated, which may be used to initiate an action. the special event trigger output of ccp1 resets the tmr1 register pair, and starts an a/d conversion (if a/d module is enabled). this allows the ccpr1 register to effectively be a 16-bit programmable period register for timer1. note: clearing the ccp1con register will force the rc2/ccp1 compare output latch to the default low level. this is not the portc i/o data latch. ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic special event trigger set flag bit ccp1if (pir1<2>) match rc2/ccp1 trisc<2> ccp1con<3:0> mode select output enable pin special event trigger will: reset timer1, but not set interrupt flag bit tmr1if (pir1<0>), and set bit go/done (adcon0<2>). note: the special event trigger from the ccp1 module will not set interrupt flag bit tmr1if (pir1<0>).
pic16f870/871 ds30569b-page 58 ? 2003 microchip technology inc. 8.4 pwm mode (pwm) in pulse width modulation mode, the ccp1 pin pro- duces up to a 10-bit resolution pwm output. since the ccp1 pin is multiplexed with the portc data latch, the trisc<2> bit must be cleared to make the ccp1 pin an output. figure 8-3 shows a simplified block diagram of the ccp module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 8.4.3. figure 8-3: simplified pwm block diagram a pwm output (figure 8-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 8-4: pwm output 8.4.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula: pwm period = [(pr2) + 1] ? 4  t osc  (tmr2 prescale value) pwm frequency is defined as 1 / [pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: tmr2 is cleared  the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set)  the pwm duty cycle is latched from ccpr1l into ccpr1h 8.4.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available. the ccpr1l contains the eight msbs and the ccp1con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time: pwm duty cycle = (ccpr1l:ccp1con<5:4>)  t osc  (tmr2 prescale value) ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read-only register. the ccpr1h register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitch-free pwm operation. when the ccpr1h and 2-bit latch match tmr2, con- catenated with an internal 2-bit q clock, or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the formula: note: clearing the ccp1con register will force the ccp1 pwm output latch to the default low level. this is not the portc i/o data latch. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (note 1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisc<2> rc2/ccp1 note 1: the 8-bit timer is concatenated with 2-bit internal q clock, or 2 bits of the prescaler, to create 10-bit time base. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 note: the timer2 postscaler (see section 7.1) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. note: if the pwm duty cycle value is longer than the pwm period, the ccp1 pin will not be cleared. log ( f pwm log(2) f osc ) bits = resolution
? 2003 microchip technology inc. ds30569b-page 59 pic16f870/871 8.4.3 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the ccp1 pin an output by clearing the trisc<2> bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. 5. configure the ccp1 module for pwm operation. table 8-2: example pwm frequencies and resolutions at 20 mhz table 8-3: registers associated with capture, compare, and timer1 pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12khz 156.3 khz 208.3 khz timer prescaler (1, 4, 16) 16 4 1 1 1 1 pr2 value 0xffh 0xffh 0xffh 0x3fh 0x1fh 0x17h maximum resolution (bits) 10 10 10 8 7 6.5 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 pspie (1) adie rcie txie ?ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 87h trisc portc data direction register 1111 1111 1111 1111 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded ce lls are not used by capture and timer1. note 1: the psp is not implemented on the pic16f870; always maintain these bits clear.
pic16f870/871 ds30569b-page 60 ? 2003 microchip technology inc. table 8-4: registers associated with pwm and timer2 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 87h trisc portc data direction register 1111 1111 1111 1111 11h tmr2 timer2 module?s register 0000 0000 0000 0000 92h pr2 timer2 module?s period register 1111 1111 1111 1111 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used by pwm and timer2. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear.
? 2003 microchip technology inc. ds30569b-page 61 pic16f870/871 9.0 addressable universal synchronous asynchronous receiver transmitter (usart) the universal synchronous asynchronous receiver transmitter (usart) module is one of the two serial i/o modules. (usart is also known as a serial com- munications interface or sci.) the usart can be con- figured as a full duplex asynchronous system that can communicate with peripheral devices, such as crt ter- minals and personal computers, or it can be configured as a half-duplex synchronous system that can commu- nicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the usart can be configured in the following modes:  asynchronous (full-duplex)  synchronous - master (half-duplex)  synchronous - slave (half-duplex) bit spen (rcsta<7>) and bits trisc<7:6> have to be set in order to configure pins rc6/tx/ck and rc7/rx/dt as the universal synchronous asynchronous receiver transmitter. the usart module also has a multi-processor communication capability using 9-bit address detection. register 9-1: txsta: transmit status and control register (address: 98h) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync ? brgh trmt tx9d bit 7 bit 0 bit 7 csrc: clock source select bit asynchronous mode: don?t care synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9 : 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen : transmit enable bit 1 = transmit enabled 0 = transmit disabled note: sren/cren overrides txen in sync mode. bit 4 sync : usart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 unimplemented: read as '0' bit 2 brgh : high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode bit 1 trmt : transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9th bit of transmit data, can be parity bit legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 62 ? 2003 microchip technology inc. register 9-2: rcsta: receive status and control register (address 18h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 bit 7 spen: serial port enable bit 1 = serial port enabled (configures rc7/rx/dt and rc6/tx/ck pins as serial port pins) 0 = serial port disabled bit 6 rx9 : 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren : single receive enable bit asynchronous mode: don?t care synchronous mode - master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode - slave: don?t care bit 4 cren : continuous receive enable bit asynchronous mode: 1 = enables continuous receive 0 = disables continuous receive synchronous mode: 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ): 1 = enables address detection, enables interrupt and load of the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received, and ninth bit can be used as parity bit bit 2 ferr : framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr : overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data (can be parity bit, but must be calculated by user firmware) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2003 microchip technology inc. ds30569b-page 63 pic16f870/871 9.1 usart baud rate generator (brg) the brg supports both the asynchronous and syn- chronous modes of the usart. it is a dedicated 8-bit baud rate generator. the spbrg register controls the period of a free running 8-bit timer. in asynchronous mode, bit brgh (txsta<2>) also controls the baud rate. in synchronous mode, bit brgh is ignored. table 9-1 shows the formula for computation of the baud rate for different usart modes which only apply in master mode (internal clock). given the desired baud rate and f osc , the nearest integer value for the spbrg register can be calculated using the formula in table 9-1. from this, the error in baud rate can be determined. it may be advantageous to use the high baud rate (brgh = 1 ), even for slower baud clocks. this is because the f osc /(16(x + 1)) equation can reduce the baud rate error in some cases. writing a new value to the spbrg register causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 9.1.1 sampling the data on the rc7/rx/dt pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 9-1: baud rate formula table 9-2: registers associated with baud rate generator sync brgh = 0 (low speed) brgh = 1 (high speed) 0 1 (asynchronous) baud rate = f osc /(64(x+1)) (synchronous) baud rate = f osc /(4(x+1)) baud rate = f osc /(16(x+1)) n/a legend: x = value in spbrg (0 to 255) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as '0'. s haded cells are not used by the brg.
pic16f870/871 ds30569b-page 64 ? 2003 microchip technology inc. table 9-3: baud rates for asynchronous mode (brgh = 0) baud rate (k) f osc = 20 mhz f osc = 16 mhz f osc = 10 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3------- -- 1.2 1.221 1.75 255 1.202 0.17 207 1.202 0.17 129 2.4 2.404 0.17 129 2.404 0.17 103 2.404 0.17 64 9.6 9.766 1.73 31 9.615 0.16 25 9.766 1.73 15 19.2 19.531 1.72 15 19.231 0.16 12 19.531 1.72 7 28.8 31.250 8.51 9 27.778 3.55 8 31.250 8.51 4 33.6 34.722 3.34 8 35.714 6.29 6 31.250 6.99 4 57.6 62.500 8.51 4 62.500 8.51 3 52.083 9.58 2 high 1.221 - 255 0.977 - 255 0.610 - 255 low 312.500 - 0 250.000 - 0 156.250 - 0 baud rate (k) f osc = 4 mhz f osc = 3.6864 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3 0.300 0 207 0.3 0 191 1.2 1.202 0.17 51 1.2 0 47 2.4 2.404 0.17 25 2.4 0 23 9.6 8.929 6.99 6 9.6 0 5 19.2 20.833 8.51 2 19.2 0 2 28.8 31.250 8.51 1 28.8 0 1 33.6 - - - - - - 57.6 62.500 8.51 0 57.6 0 0 high 0.244 - 255 0.225 - 255 low 62.500 - 0 57.6 - 0
? 2003 microchip technology inc. ds30569b-page 65 pic16f870/871 table 9-4: baud rates for asynchronous mode (brgh = 1) baud rate (k) f osc = 20 mhz f osc = 16 mhz f osc = 10 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3--------- 1.2--------- 2.4 - - - - - - 2.441 1.71 255 9.6 9.615 0.16 129 9.615 0.16 103 9.615 0.16 64 19.2 19.231 0.16 64 19.231 0.16 51 19.531 1.72 31 28.8 29.070 0.94 42 29.412 2.13 33 28.409 1.36 21 33.6 33.784 0.55 36 33.333 0.79 29 32.895 2.10 18 57.6 59.524 3.34 20 58.824 2.13 16 56.818 1.36 10 high 4.883 - 255 3.906 - 255 2.441 - 255 low 1250.000 - 0 1000.000 0 625.000 - 0 baud rate (k) f osc = 4 mhz f osc = 3.6864 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3------ 1.2 1.202 0.17 207 1.2 0 191 2.4 2.404 0.17 103 2.4 0 95 9.6 9.615 0.16 25 9.6 0 23 19.2 19.231 0.16 12 19.2 0 11 28.8 27.798 3.55 8 28.8 0 7 33.6 35.714 6.29 6 32.9 2.04 6 57.6 62.500 8.51 3 57.6 0 3 high 0.977 - 255 0.9 - 255 low 250.000 - 0 230.4 - 0
pic16f870/871 ds30569b-page 66 ? 2003 microchip technology inc. 9.2 usart asynchronous mode in this mode, the usart uses standard non-return-to- zero (nrz) format (one start bit, eight or nine data bits, and one stop bit). the most common data format is 8-bits. an on-chip, dedicated, 8-bit baud rate gener- ator can be used to derive standard baud rate frequen- cies from the oscillator. the usart transmits and receives the lsb first. the transmitter and receiver are functionally independent, but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate, depending on bit brgh (txsta<2>). parity is not supported by the hardware, but can be implemented in software (and stored as the ninth data bit). asynchronous mode is stopped during sleep. asynchronous mode is selected by clearing bit sync (txsta<4>). the usart asynchronous module consists of the following important elements:  baud rate generator  sampling circuit  asynchronous transmitter  asynchronous receiver 9.2.1 usart asynchronous transmitter the usart transmitter block diagram is shown in figure 9-1. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and flag bit txif (pir1<4>) is set. this interrupt can be enabled/disabled by setting/clearing enable bit txie ( pie1<4>). flag bit txif will be set, regardless of the state of enable bit txie and cannot be cleared in soft- ware. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. status bit trmt is a read only bit, which is set when the tsr register is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr register is empty. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data and the baud rate generator (brg) has produced a shift clock (figure 9-2). the transmission can also be started by first loading the txreg register and then setting enable bit txen. normally, when transmission is first started, the tsr register is empty. at that point, transfer to the txreg register will result in an immedi- ate transfer to tsr, resulting in an empty txreg. a back-to-back transfer is thus possible (figure 9-3). clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. as a result, the rc6/tx/ck pin will revert to hi-impedance. in order to select 9-bit transmission, transmit bit tx9 (txsta<6>) should be set and the ninth bit should be written to tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg reg- ister. this is because a data write to the txreg regis- ter can result in an immediate transfer of the data to the tsr register (if the tsr is empty). in such a case, an incorrect ninth data bit may be loaded in the tsr register. figure 9-1: usart transmit block diagram note 1: the tsr register is not mapped in data memory, so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. txif is cleared by loading txreg. txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen rc6/tx/ck pin pin buffer and control 8 ? ? ?
? 2003 microchip technology inc. ds30569b-page 67 pic16f870/871 when setting up an asynchronous transmission, follow these steps: 1. initialize the spbrg register for the appropriate baud rate. if a high speed baud rate is desired, set bit brgh (section 9.1). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, then set enable bit txie. 4. if 9-bit transmission is desired, then set transmit bit tx9. 5. enable the transmission by setting bit txen, which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. figure 9-2: asynchronous master transmission figure 9-3: asynchronous master transmission (back to back) table 9-5: registers associated with asynchronous transmission address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren ? ferr oerr rx9d 0000 -00x 0000 -00x 19h txreg usart transmit register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as '0'. shaded cells are not used for asynchronous transmission. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear. word 1 stop bit word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) rc6/tx/ck (pin) txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) transmit shift reg. write to txreg brg output (shift clock) rc6/tx/ck (pin) txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows tw o consecutive transmissions.
pic16f870/871 ds30569b-page 68 ? 2003 microchip technology inc. 9.2.2 usart asynchronous receiver the receiver block diagram is shown in figure 9-4. the data is received on the rc7/rx/dt pin and drives the data recovery block. the data recovery block is actually a high speed shifter, operating at x16 times the baud rate; whereas, the main receive serial shifter operates at the bit rate or at f osc . once asynchronous mode is selected, reception is enabled by setting bit cren (rcsta<4>). the heart of the receiver is the receive (serial) shift register (rsr). after sampling the stop bit, the received data in the rsr is transferred to the rcreg register (if it is empty). if the transfer is complete, flag bit rcif (pir1<5>) is set. the actual interrupt can be enabled/disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read only bit, which is cleared by the hardware. it is cleared when the rcreg register has been read and is empty. the rcreg is a double-buffered register (i.e., it is a two-deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting to the rsr register. on the detection of the stop bit of the third byte, if the rcreg register is still full, the overrun error bit oerr (rcsta<1>) will be set. the word in the rsr will be lost. the rcreg reg- ister can be read twice to retrieve the two bytes in the fifo. overrun bit oerr has to be cleared in software. this is done by resetting the receive logic (cren is cleared and then set). if bit oerr is set, transfers from the rsr register to the rcreg register are inhibited, and no further data will be received. it is therefore, essential to clear error bit oerr if it is set. framing error bit ferr (rcsta<2>) is set if a stop bit is detected as clear. bit ferr and the 9th receive bit are buffered the same way as the receive data. reading the rcreg will load bits rx9d and ferr with new values, therefore, it is essential for the user to read the rcsta register before reading the rcreg register in order not to lose the old ferr and rx9d information. figure 9-4: usart receive block diagram figure 9-5: asynchronous reception x64 baud rate clk spbrg baud rate generator rc7/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? f osc start bit bit7/8 bit1 bit0 bit7/8 bit0 stop bit start bit start bit bit7/8 stop bit rx (pin) reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word, causing the oerr (overrun) bit to be set.
? 2003 microchip technology inc. ds30569b-page 69 pic16f870/871 when setting up an asynchronous reception, follow these steps: 1. initialize the spbrg register for the appropriate baud rate. if a high speed baud rate is desired, set bit brgh (section 9.1). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, then set enable bit rcie. 4. if 9-bit reception is desired, then set bit rx9. 5. enable the reception by setting bit cren. 6. flag bit rcif will be set when reception is com- plete and an interrupt will be generated if enable bit rcie is set. 7. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing enable bit cren. 10. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 9-6: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren ? ferr oerr rx9d 0000 -00x 0000 -00x 1ah rcreg usart receive register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as '0'. shaded cells are not used for asynchronous reception. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear.
pic16f870/871 ds30569b-page 70 ? 2003 microchip technology inc. 9.2.3 setting up 9-bit mode with address detect when setting up an asynchronous reception with address detect enabled:  initialize the spbrg register for the appropriate baud rate. if a high speed baud rate is desired, set bit brgh.  enable the asynchronous serial port by clearing bit sync and setting bit spen.  if interrupts are desired, then set enable bit rcie.  set bit rx9 to enable 9-bit reception.  set adden to enable address detect.  enable the reception by setting enable bit cren.  flag bit rcif will be set when reception is com- plete, and an interrupt will be generated if enable bit rcie was set.  read the rcsta register to get the ninth bit and determine if any error occurred during reception.  read the 8-bit received data by reading the rcreg register, to determine if the device is being addressed.  if any error occurred, clear the error by clearing enable bit cren.  if the device has been addressed, clear the adden bit to allow data bytes and address bytes to be read into the receive buffer, and interrupt the cpu. figure 9-6: usart receive block diagram x64 baud rate clk spbrg baud rate generator rc7/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? rx9 adden rx9 adden rsr<8> enable load of receive buffer 8 8 f osc
? 2003 microchip technology inc. ds30569b-page 71 pic16f870/871 figure 9-7: asynchronous reception with address detect figure 9-8: asynchronous reception with address byte first table 9-7: registers associated with asynchronous reception start bit bit1 bit0 bit8 bit0 stop bit start bit bit8 stop bit rc7/rx/dt (pin) load rsr read rcif word 1 rcreg bit8 = 0 , data byte bit8 = 1 , address byte note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because adden = 1 . start bit bit1 bit0 bit8 bit0 stop bit start bit bit8 stop bit rc7/rx/dt (pin) load rsr read rcif word 1 rcreg bit8 = 1 , address byte bit8 = 0 , data byte note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because adden was not updated and still = 0 . address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as '0'. shaded ce lls are not used for asynchronous reception. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear.
pic16f870/871 ds30569b-page 72 ? 2003 microchip technology inc. 9.3 usart synchronous master mode in synchronous master mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition, enable bit spen (rcsta<7>) is set in order to configure the rc6/tx/ck and rc7/rx/dt i/o pins to ck (clock) and dt (data) lines, respectively. the master mode indicates that the processor transmits the master clock on the ck line. the master mode is entered by setting bit csrc (txsta<7>). 9.3.1 usart synchronous master transmission the usart transmitter block diagram is shown in figure 9-6. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one t cycle ), the txreg is empty and inter- rupt bit txif (pir1<4>) is set. the interrupt can be enabled/disabled by setting/clearing enable bit txie (pie1<4>). flag bit txif will be set, regardless of the state of enable bit txie and cannot be cleared in soft- ware. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit trmt (txsta<1>) shows the status of the tsr register. trmt is a read only bit which is set when the tsr is empty. no inter- rupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory, so it is not available to the user. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data. the first data bit will be shifted out on the next available rising edge of the clock on the ck line. data out is sta- ble around the falling edge of the synchronous clock (figure 9-9). the transmission can also be started by first loading the txreg register and then setting bit txen (figure 9-10). this is advantageous when slow baud rates are selected, since the brg is kept in reset when bits txen, cren and sren are clear. setting enable bit txen will start the brg, creating a shift clock immediately. normally, when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate transfer to tsr, resulting in an empty txreg. back-to-back transfers are possible. clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. the dt and ck pins will revert to hi- impedance. if either bit cren or bit sren is set during a transmission, the transmission is aborted and the dt pin reverts to a hi-impedance state (for a reception). the ck pin will remain an output if bit csrc is set (internal clock). the transmitter logic, however, is not reset, although it is disconnected from the pins. in order to reset the transmitter, the user has to clear bit txen. if bit sren is set (to interrupt an on-going transmission and receive a single word), then after the single word is received, bit sren will be cleared and the serial port will revert back to transmitting, since bit txen is still set. the dt line will immediately switch from hi- impedance receive mode to transmit and start driving. to avoid this, bit txen should be cleared. in order to select 9-bit transmission, the tx9 (txsta<6>) bit should be set and the ninth bit should be written to bit tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg can result in an immediate transfer of the data to the tsr register (if the tsr is empty). if the tsr was empty and the txreg was written before writing the ?new? tx9d, the ?present? value of bit tx9d is loaded. steps to follow when setting up a synchronous master transmission: 1. initialize the spbrg register for the appropriate baud rate (section 9.1). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set.
? 2003 microchip technology inc. ds30569b-page 73 pic16f870/871 table 9-8: registers associated with synchronous master transmission figure 9-9: synchronous transmission figure 9-10: synchronous transmission (through txen) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren ? ferr oerr rx9d 0000 -00x 0000 -00x 19h txreg usart transmit register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as '0'. shaded cells ar e not used for synchronous master transmission. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear. bit 0 bit 1 bit 7 word 1 q1q2 q3q4 q1 q2q3 q4 q1 q2q3 q4 q1 q2q3 q4 q1 q2 q3q4 q3q4 q1q2 q3q4 q1q2 q3q4 q1q2 q3 q4 q1 q2q3 q4 q1 q2q3 q4 q1 q2q3 q4 bit 2 bit 0 bit 1 bit 7 rc7/rx/dt pin rc6/tx/ck pin write to txreg reg txif bit (interrupt flag) txen bit '1' '1' word 2 trmt bit write word1 write word2 note: sync master mode; spbrg = 0 . continuous transmission of two 8-bit words. rc7/rx/dt pin rc6/tx/ck pin write to txreg reg txif bit trmt bit bit0 bit1 bit2 bit6 bit7 txen bit
pic16f870/871 ds30569b-page 74 ? 2003 microchip technology inc. 9.3.2 usart synchronous master reception once synchronous mode is selected, reception is enabled by setting either enable bit sren (rcsta<5>), or enable bit cren (rcsta<4>). data is sampled on the rc7/rx/dt pin on the falling edge of the clock. if enable bit sren is set, then only a single word is received. if enable bit cren is set, the recep- tion is continuous until cren is cleared. if both bits are set, cren takes precedence. after clocking the last bit, the received data in the receive shift register (rsr) is transferred to the rcreg register (if it is empty). when the transfer is complete, interrupt flag bit rcif (pir1<5>) is set. the actual interrupt can be enabled/ disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read only bit, which is reset by the hardware. in this case, it is reset when the rcreg register has been read and is empty. the rcreg is a double-buffered register (i.e., it is a two- deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting into the rsr register. on the clocking of the last bit of the third byte, if the rcreg register is still full, then overrun error bit oerr (rcsta<1>) is set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. bit oerr has to be cleared in software (by clearing bit cren). if bit oerr is set, transfers from the rsr to the rcreg are inhibited, so it is essential to clear bit oerr if it is set. the ninth receive bit is buffered the same way as the receive data. reading the rcreg register will load bit rx9d with a new value, therefore, it is essential for the user to read the rcsta register before reading rcreg, in order not to lose the old rx9d information. when setting up a synchronous master reception: 1. initialize the spbrg register for the appropriate baud rate (section 9.1). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, then set enable bit rcie. 5. if 9-bit reception is desired, then set bit rx9. 6. if a single reception is required, set bit sren. for continuous reception, set bit cren. 7. interrupt flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 8. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set.
? 2003 microchip technology inc. ds30569b-page 75 pic16f870/871 table 9-9: registers associated with synchronous master reception figure 9-11: synchronous reception (master mode, sren) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren ? ferr oerr rx9d 0000 -00x 0000 -00x 1ah rcreg usart receive register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as '0'. shaded cells ar e not used for synchronous master reception. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear. cren bit rc7/rx/dt pin rc6/tx/ck pin write to bit sren sren bit rcif bit (interrupt) read rxreg note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brg = 0 . q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4q1 q2 q3 q4 q1 q2 q3 q4q1 q2 q3 q4 q1 q2 q3 q4q1 q2 q3 q4 q1 q2 q3 q4 '0' bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 '0' q1 q2 q3 q4
pic16f870/871 ds30569b-page 76 ? 2003 microchip technology inc. 9.4 usart synchronous slave mode synchronous slave mode differs from the master mode in the fact that the shift clock is supplied externally at the rc6/tx/ck pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in sleep mode. slave mode is entered by clearing bit csrc (txsta<7>). 9.4.1 usart synchronous slave transmit the operation of the synchronous master and slave modes is identical, except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep and if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). when setting up a synchronous slave transmission, follow these steps: 1. enable the synchronous slave serial port by set- ting bits sync and spen and clearing bit csrc. 2. clear bits cren and sren. 3. if interrupts are desired, then set enable bit txie. 4. if 9-bit transmission is desired, then set bit tx9. 5. enable the transmission by setting enable bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 9-10: registers associated with synchronous slave transmission address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as '0'. shaded cells ar e not used for synchronous slave transmission. note 1: bits pspie and pspif are reserved on the pic16f870; always maintain these bits clear.
? 2003 microchip technology inc. ds30569b-page 77 pic16f870/871 9.4.2 usart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of the sleep mode. bit sren is a ?don't care? in slave mode. if receive is enabled by setting bit cren prior to the sleep instruction, then a word may be received during sleep. on completely receiving the word, the rsr register will transfer the data to the rcreg register and if enable bit rcie bit is set, the interrupt generated will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). when setting up a synchronous slave reception, follow these steps: 1. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 2. if interrupts are desired, set enable bit rcie. 3. if 9-bit reception is desired, set bit rx9. 4. to enable reception, set enable bit cren. 5. flag bit rcif will be set when reception is com- plete and an interrupt will be generated, if enable bit rcie was set. 6. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcreg register. 8. if any error occurred, clear the error by clearing bit cren. 9. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 9-11: registers associated with synchronous slave reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf r0if 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive register 0000 0000 0000 0000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as '0'. shaded cells are not used for synchronous slave reception. note 1: bits pspie and pspif are reserved on the pic16f870, always maintain these bits clear.
pic16f870/871 ds30569b-page 78 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 79 pic16f870/871 10.0 analog-to-digital (a/d) converter module the analog-to-digital (a/d) converter module has five inputs for the 28-pin devices and eight for the other devices. the analog input charges a sample and hold capacitor. the output of the sample and hold capacitor is the input into the converter. the converter then generates a dig- ital result of this analog level via successive approxima- tion. the a/d conversion of the analog input signal results in a corresponding 10-bit digital number. the a/d module has high and low voltage reference input that is software selectable to some combination of v dd , v ss , ra2, or ra3. the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to oper- ate in sleep, the a/d clock must be derived from the a/d?s internal rc oscillator. the a/d module has four registers. these registers are:  a/d result high register (adresh)  a/d result low register (adresl)  a/d control register0 (adcon0)  a/d control register1 (adcon1) the adcon0 register, shown in register 10-1, con- trols the operation of the a/d module. the adcon1 register, shown in register 10-2, configures the func- tions of the port pins. the port pins can be configured as analog inputs (ra3 can also be the voltage reference), or as digital i/o. additional information on using the a/d module can be found in the picmicro? mid-range mcu family reference manual (ds33023). register 10-1: adcon0 register (address: 1fh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 adcs1 adcs0 chs2 chs1 chs0 go/done ?adon bit 7 bit 0 bit 7-6 adcs1:adcs0: a/d conversion clock select bits 00 = f osc /2 01 = f osc /8 10 = f osc /32 11 = f rc (clock derived from the internal a/d module rc oscillator) bit 5-3 chs2:chs0 : analog channel select bits 000 = channel 0, (ra0/an0) 010 = channel 2, (ra2/an2) 011 = channel 3, (ra3/an3) 100 = channel 4, (ra5/an4) 101 = channel 5, (re0/an5) (1) 110 = channel 6, (re1/an6) (1) 111 = channel 7, (re2/an7) (1) bit 2 go/done : a/d conversion status bit if adon = 1 : 1 = a/d conversion in progress (setting this bit starts the a/d conversion) 0 = a/d conversion not in progress (this bit is automatically cleared by hardware when the a/d conversion is complete) bit 1 unimplemented : read as '0' bit 0 adon : a/d on bit 1 = a/d converter module is operating 0 = a/d converter module is shut-off and consumes no operating current note 1: these channels are not available on the pic16f870 device. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f870/871 ds30569b-page 80 ? 2003 microchip technology inc. register 10-2: adcon1 register (address: 9fh) the adresh:adresl registers contain the 10-bit result of the a/d conversion. when the a/d conversion is complete, the result is loaded into this a/d result reg- ister pair, the go/done bit (adcon0<2>) is cleared and the a/d interrupt flag bit adif is set. the block diagram of the a/d module is shown in figure 10-1. after the a/d module has been configured as desired, the selected channel must be acquired before the con- version is started. the analog input channels must have their corresponding tris bits selected as inputs. to determine sample time, see section 10.1. after this acquisition time has elapsed, the a/d conversion can be started. u-0 u-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 bit 7 adfm: a/d result format select bit 1 = right justified. 6 most significant bits of adresh are read as ?0?. 0 = left justified. 6 least significant bits of adresl are read as ?0?. bit 6-4 unimplemented: read as '0' bit 3-0 pcfg3:pcfg0 : a/d port configuration control bits: note 1: these channels are not available on the pic16f870 device. 2: this column indicates the number of analog channels available as a/d inputs and the number of analog channels used as voltage reference inputs. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown a = analog input d = digital i/o pcfg3: pcfg0 an7 (1) re2 an6 (1) re1 an5 (1) re0 an4 ra5 an3 ra3 an2 ra2 an1 ra1 an0 ra0 v ref +v ref - c han / refs (2) 0000 aaaa a aaav dd v ss 8/0 0001 aaaav ref +a a a ra3v ss 7/1 0010 ddda a aaav dd v ss 5/0 0011 dddav ref +a a a ra3v ss 4/1 0100 dddd a daav dd v ss 3/0 0101 ddddv ref +d a a ra3v ss 2/1 011x dddd d dddv dd v ss 0/0 1000 aaaav ref +v ref -a a ra3ra2 6/2 1001 ddaa a aaav dd v ss 6/0 1010 ddaav ref +a a a ra3v ss 5/1 1011 ddaav ref +v ref -a a ra3ra2 4/2 1100 dddav ref +v ref -a a ra3ra2 3/2 1101 ddddv ref +v ref -a a ra3ra2 2/2 1110 dddd d ddav dd v ss 1/0 1111 ddddv ref +v ref -d a ra3ra2 1/2
? 2003 microchip technology inc. ds30569b-page 81 pic16f870/871 these steps should be followed for doing an a/d conversion: 1. configure the a/d module:  configure analog pins/voltage reference and digital i/o (adcon1)  select a/d input channel (adcon0)  select a/d conversion clock (adcon0)  turn on a/d module (adcon0) 2. configure a/d interrupt (if desired):  clear adif bit  set adie bit  set peie bit  set gie bit 3. wait the required acquisition time. 4. start conversion:  set go/done bit (adcon0) 5. wait for a/d conversion to complete, by either:  polling for the go/done bit to be cleared (with interrupts enabled); or  waiting for the a/d interrupt 6. read a/d result register pair (adresh:adresl), clear bit adif if required. 7. for the next conversion, go to step 1 or step 2, as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before the next acquisition starts. figure 10-1: a/d block diagram (input voltage) v ain v ref + (reference voltage) v dd pcfg3:pcfg0 chs2:chs0 re2/an7 (1) re1/an6 (1) re0/an5 (1) ra5/an4 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 111 110 101 100 011 010 001 000 a/d converter note 1: not available on the pic16f870 device. v ref - (reference voltage) v ss pcfg3:pcfg0
pic16f870/871 ds30569b-page 82 ? 2003 microchip technology inc. 10.1 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 10-2. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ), see figure 10-2. the maximum recom- mended impedance for analog sources is 10 k ? . as the impedance is decreased, the acquisition time may be decreased. after the analog input channel is selected (changed), this acquisition must be done before the conversion can be started. to calculate the minimum acquisition time, equation 10-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. to calculate the minimum acquisition time, t acq , see the picmicro? mid-range mcu family reference manual (ds33023). equation 10-1: acquisition time figure 10-2: analog input model t acq t c t acq = = = = = = = = amplifier settling time + hold capacitor charging time + temperature coefficient t amp + t c + t coff 2 s + t c + [(temperature ? 25 c)(0.05 s/c)] c hold (r ic + r ss + r s ) in(1/2047) - 120 pf (1 k ? + 7 k ? + 10 k ? ) in(0.0004885) 16.47 s 2 s + 16.47 s + [(50c ? 25 c)(0.05 s/ c) 19.72 s note 1: the reference voltage (v ref ) has no effect on the equation, since it cancels itself out. 2: the charge holding capacitor (c hold ) is not discharged after each conversion. 3: the maximum recommended impedance for analog sources is 10 k ? . this is required to meet the pin leakage specification. 4: after a conversion has completed, a 2.0 t ad delay must complete before acquisition can begin again. during this time, the holding capacitor is not connected to the selected a/d input channel. c pin va r s anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = dac capacitance v ss 6v sampling switch 5v 4v 3v 2v 567891011 (k ? ) v dd = 120 pf 500 na legend c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions
? 2003 microchip technology inc. ds30569b-page 83 pic16f870/871 10.2 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires a minimum 12 t ad per 10-bit conversion. the source of the a/d conversion clock is software selected. the four possible options for t ad are: 2 t osc 8 t osc 32 t osc  internal a/d module rc oscillator (2-6 s) for correct a/d conversions, the a/d conversion clock (t ad ) must be selected to ensure a minimum t ad time of 1.6 s. table 10-1 shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. table 10-1: t ad vs. maximum device operating frequencies (standard devices (c)) 10.3 configuring analog port pins the adcon1 and tris registers control the operation of the a/d port pins. the port pins that are desired as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs2:chs0 bits and the tris bits. ad clock source (t ad ) maximum device frequency operation adcs1:adcs0 max. 2 t osc 00 1.25 mhz 8 t osc 01 5 mhz 32 t osc 10 20 mhz rc (1, 2, 3) 11 (note 1) note 1: the rc source has a typical t ad time of 4 s, but can vary between 2-6 s. 2: when the device frequencies are greater than 1 mhz, the rc a/d conversion clock source is only recommended for sleep operation. 3: for extended voltage devices (lc), please refer to the electrical characteristics (section 14.1 and 14.2). note 1: when reading the port register, any pin configured as an analog input channel will read as cleared (a low level). pins config- ured as digital inputs will convert an ana- log input. analog levels on a digitally configured input will not affect the conversion accuracy. 2: analog levels on any pin that is defined as a digital input (including the an7:an0 pins), may cause the input buffer to con- sume current that is out of the device specifications.
pic16f870/871 ds30569b-page 84 ? 2003 microchip technology inc. 10.4 a/d conversions clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. that is, the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is aborted, a 2 t ad wait is required before the next acquisition is started. after this 2 t ad wait, acquisition on the selected channel is automatically started. the go/done bit can then be set to start the conversion. in figure 10-3, after the go bit is set, the first time segment has a minimum of t cy and a maximum of t ad . figure 10-3: a/d conversion t ad cycles 10.4.1 a/d result registers the adresh:adresl register pair is the location where the 10-bit a/d result is loaded at the completion of the a/d conversion. this register pair is 16-bits wide. the a/d module gives the flexibility to left or right justify the 10-bit result in the 16-bit result register. the a/d for- mat select bit (adfm) controls this justification. figure 10-4 shows the operation of the a/d result justifi- cation. the extra bits are loaded with ?0?. when an a/d result will not overwrite these locations (a/d disable), these registers may be used as two general purpose 8-bit registers. figure 10-4: a/d result justification note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 9 set go bit holding capacitor is disconnected fr om analog input (typically 100 ns) b9 b8 b7 b6 b5 b4 b3 b2 t ad 10 t ad 11 b1 b0 t cy to t ad conversion starts adres is loaded go bit is cleared adif bit is set holding capacitor is connected to analog input 10-bit result adresh adresl 0000 00 adfm = 0 0 2 1 0 7 7 10-bit result adresh adresl 10-bit result 0000 00 7 0 7 6 5 0 adfm = 1 right justified left justified
? 2003 microchip technology inc. ds30569b-page 85 pic16f870/871 10.5 a/d operation during sleep the a/d module can operate during sleep mode. this requires that the a/d clock source be set to rc (adcs1:adcs0 = 11 ). when the rc clock source is selected, the a/d module waits one instruction cycle before starting the conversion. this allows the sleep instruction to be executed, which eliminates all digital switching noise from the conversion. when the conver- sion is completed, the go/done bit will be cleared and the result loaded into the adres register. if the a/d interrupt is enabled, the device will wake-up from sleep. if the a/d interrupt is not enabled, the a/d mod- ule will then be turned off, although the adon bit will remain set. when the a/d clock source is another clock option (not rc), a sleep instruction will cause the present conver- sion to be aborted and the a/d module to be turned off, though the adon bit will remain set. turning off the a/d places the a/d module in its lowest current consumption state. 10.6 effects of a reset a device reset forces all registers to their reset state. this forces the a/d module to be turned off, and any conversion is aborted. all a/d input pins are configured as analog inputs. the value that is in the adresh:adresl registers is not modified for a power-on reset. the adresh:adresl registers will contain unknown data after a power-on reset. table 10-2: registers/bits associated with a/d note: for the a/d module to operate in sleep, the a/d clock source must be set to rc (adcs1:adcs0 = 11 ). to allow the con- version to occur during sleep, ensure the sleep instruction immediately follows the instruction that sets the go/done bit. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on mclr , wdt 0bh,8bh, 10bh,18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 pspif (1) adif rcif txif ? ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 pspie (1) adie rcie txie ? ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 1eh adresh a/d result register high byte xxxx xxxx uuuu uuuu 9eh adresl a/d result register low byte xxxx xxxx uuuu uuuu 1fh adcon0 adcs1 adcs0 chs2 chs1 chs0 go/done ?adon 0000 00-0 0000 00-0 9fh adcon1 adfm ? ? ?pcfg3pcfg2pcfg1pcfg0 --0- 0000 --0- 0000 85h trisa ? ? porta data direction register --11 1111 --11 1111 05h porta ? ? porta data latch when written: porta pins when read --0x 0000 --0u 0000 89h (1) trise ibf obf ibov pspmode ? porte data direction bits 0000 -111 0000 -111 09h (1) porte ? ? ? ? ? re2 re1 re0 ---- -xxx ---- -uuu legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used for a/d conversion. note 1: these registers/bits are not available on the 28-pin devices.
pic16f870/871 ds30569b-page 86 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 87 pic16f870/871 11.0 special features of the cpu the pic16f870/871 devices have a host of features intended to maximize system reliability, minimize cost through elimination of external components, provide power saving operating modes and offer code protection. these are:  oscillator selection  reset - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor)  interrupts  watchdog timer (wdt)  sleep  code protection  id locations  in-circuit serial programming  low voltage in-circuit serial programming  in-circuit debugger pic16f870/871 devices have a watchdog timer, which can be shut-off only through configuration bits. it runs off its own rc oscillator for added reliability. there are two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which provides a fixed delay of 72 ms (nomi- nal) on power-up only. it is designed to keep the part in reset while the power supply stabilizes. with these two timers on-chip, most applications need no external reset circuitry. sleep mode is designed to offer a very low current power-down mode. the user can wake-up from sleep through external reset, watchdog timer wake-up, or through an interrupt. several oscillator options are also made available to allow the part to fit the application. the rc oscillator option saves system cost while the lp crystal option saves power. a set of configuration bits is used to select various options. additional information on special features is available in the picmicro? mid-range mcu family reference manual (ds33023). 11.1 configuration bits the configuration bits can be programmed (read as '0'), or left unprogrammed (read as '1'), to select various device configurations. the erased, or unprogrammed value of the configuration word is 3fffh. these bits are mapped in program memory location 2007h. it is important to note that address 2007h is beyond the user program memory space, which can be accessed only during programming.
pic16f870/871 ds30569b-page 88 ? 2003 microchip technology inc. register 11-1: configuration word (address 2007h) (1) cp1 cp0 debug ? wrt cpd lvp boren cp1 cp0 pwrten wdten fosc1 fosc0 bit 13 bit 0 bit 13-12, bit 5-4 cp1:cp0: flash program memory code protection bits (2) 11 = code protection off 10 = not supported 01 = not supported 00 = code protection on bit 11 debug: in-circuit debugger mode 1 = in-circuit debugger disabled, rb6 and rb7 are general purpose i/o pins 0 = in-circuit debugger enabled, rb6 and rb7 are dedicated to the debugger bit 10 unimplemented: read as ?1? bit 9 wrt: flash program memory write enable 1 = unprotected program memory may be written to by eecon control 0 = unprotected program memory may not be written to by eecon control bit 8 cpd: data ee memory code protection 1 = code protection off 0 = data eeprom memory code protected bit 7 lvp : low voltage in-circuit serial programming enable bit 1 = rb3/pgm pin has pgm function, low voltage programming enabled 0 = rb3 is digital i/o, hv on mclr must be used for programming bit 6 boren : brown-out reset enable bit (3) 1 = bor enabled 0 = bor disabled bit 3 pwrten : power-up timer enable bit (3) 1 = pwrt disabled 0 = pwrt enabled bit 2 wdten : watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled bit 1-0 fosc1:fosc0 : oscillator selection bits 11 = rc oscillator 10 = hs oscillator 01 = xt oscillator 00 = lp oscillator legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note 1: the erased (unprogrammed) value of the configuration word is 3fffh. 2: all of the cp1:cp0 pairs have to be given the same value to enable the code protection scheme listed. 3: enabling brown-out reset automatically enables power-up timer (pwrt), regardless of the value of bit pwrten . ensure the power-up timer is enabled any time brown-out reset is enabled.
? 2003 microchip technology inc. ds30569b-page 89 pic16f870/871 11.2 oscillator configurations 11.2.1 oscillator types the pic16f870/871 can be operated in four different oscillator modes. the user can program two configura- tion bits (fosc1 and fosc0) to select one of these four modes:  lp low power crystal  xt crystal/resonator  hs high speed crystal/resonator  rc resistor/capacitor 11.2.2 crystal oscillator/ceramic resonators in xt, lp or hs modes, a crystal or ceramic resonator is connected to the osc1/clki and osc2/clko pins to establish oscillation (figure 11-1). the pic16f870/ 871 oscillator design requires the use of a parallel cut crystal. use of a series cut crystal may give a frequency out of the crystal manufacturers specifications. when in xt, lp or hs modes, the device can have an external clock source to drive the osc1/clki pin (figure 11-2). figure 11-1: crystal/ceramic resonator operation (hs, xt or lp osc configuration) figure 11-2: external clock input operation (hs, xt or lp osc configuration) table 11-1: ceramic resonators note 1: see table 11-1 and table 11-2 for recommended values of c1 and c2. 2: a series resistor ( r s ) may be required for at strip cut crystals. 3: rf varies with the crystal chosen. c1 (1) c2 (1) xtal osc2 osc1 rf (3) sleep to logic pic16f870/871 r s (2) internal ranges tested: mode freq. osc1 osc2 xt 455 khz 2.0 mhz 4.0 mhz 68 - 100 pf 15 - 68 pf 15 - 68 pf 68 - 100 pf 15 - 68 pf 15 - 68 pf hs 8.0 mhz 16.0 mhz 10 - 68 pf 10 - 22 pf 10 - 68 pf 10 - 22 pf these values are for design guidance only. see notes following table 11-2. resonators used: 455 khz panasonic efo-a455k04b 0.3% 2.0 mhz murata erie csa2.00mg 0.5% 4.0 mhz murata erie csa4.00mg 0.5% 8.0 mhz murata erie csa8.00mt 0.5% 16.0 mhz murata erie csa16.00mx 0.5% all resonators used did not have built-in capacitors. osc1 osc2 open clock from ext. system pic16f870/871
pic16f870/871 ds30569b-page 90 ? 2003 microchip technology inc. table 11-2: capacitor selection for crystal oscillator 11.2.3 rc oscillator for timing insensitive applications, the ?rc? device option offers additional cost savings. the rc oscillator frequency is a function of the supply voltage, the resis- tor (r ext ) and capacitor (c ext ) values, and the operat- ing temperature. in addition to this, the oscillator frequency will vary from unit to unit due to normal pro- cess parameter variation. furthermore, the difference in lead frame capacitance between package types will also affect the oscillation frequency, especially for low c ext values. the user also needs to take into account variation due to tolerance of external r and c components used. figure 11-3 shows how the r/c combination is connected to the pic16f870/871. figure 11-3: rc oscillator mode osc type crystal freq. cap. range c1 cap. range c2 lp 32 khz 33 pf 33 pf 200 khz 15 pf 15 pf xt 200 khz 47-68 pf 47-68 pf 1 mhz 15 pf 15 pf 4 mhz 15 pf 15 pf hs 4 mhz 15 pf 15 pf 8 mhz 15-33 pf 15-33 pf 20 mhz 15-33 pf 15-33 pf these values are for design guidance only. see notes following this table. crystals used 32 khz epson c-001r32.768k-a 20 ppm 200 khz std xtl 200.000khz 20 ppm 1 mhz ecs ecs-10-13-1 50 ppm 4 mhz ecs ecs-40-20-1 50 ppm 8 mhz epson ca-301 8.000m-c 30 ppm 20 mhz epson ca-301 20.000m-c 30 ppm note 1: higher capacitance increases the stability of oscillator, but also increases the start-up time. 2: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 3: r s may be required in hs mode, as well as xt mode, to avoid overdriving crystals with low drive level specification. 4: when migrating from other picmicro ? devices, oscillator performance should be verified. osc2/clko c ext r ext pic16f870/871 osc1 f osc /4 internal clock v dd v ss recommended values: 3 k ? r ext 100 k ? c ext > 20pf
? 2003 microchip technology inc. ds30569b-page 91 pic16f870/871 11.3 reset the pic16f870/871 differentiates between various kinds of reset:  power-on reset (por) mclr reset during normal operation mclr reset during sleep  wdt reset (during normal operation)  wdt wake-up (during sleep)  brown-out reset (bor) some registers are not affected in any reset condi- tion. their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on power-on reset (por), on the mclr and wdt reset, on mclr reset during sleep, and brown-out reset (bor). they are not affected by a wdt wake-up, which is viewed as the resumption of normal operation. the to and pd bits are set or cleared differently in different reset situa- tions, as indicated in table 11-4. these bits are used in software to determine the nature of the reset. see table 11-6 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 11-4. these devices have a mclr noise filter in the mclr reset path. the filter will detect and ignore small pulses. it should be noted that a wdt reset does not drive mclr pin low. figure 11-4: simplified block diagram of on-chip reset circuit s rq external reset mclr v dd osc1 wdt module v dd rise detect ost/pwrt on-chip rc osc wdt time-out power-on reset ost 10-bit ripple counter pwrt chip_reset 10-bit ripple counter reset enable ost enable pwrt sleep note 1: this is a separate oscillator from the rc oscillator of the clki pin. brown-out reset boren (1)
pic16f870/871 ds30569b-page 92 ? 2003 microchip technology inc. 11.4 power-on reset (por) a power-on reset pulse is generated on-chip when v dd rise is detected (in the range of 1.2v - 1.7v). to take advantage of the por, tie the mclr pin directly (or through a resistor) to v dd . this will eliminate external rc components usually needed to create a power-on reset. a maximum rise time for v dd is specified. see electrical specifications for details. when the device starts normal operation (exits the reset condition), device operating parameters (volt- age, frequency, temperature,...) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. brown-out reset may be used to meet the start-up conditions. for additional information, refer to application note, an007, ?power-up trouble shooting? (ds00007). 11.5 power-up timer (pwrt) the power-up timer provides a fixed 72 ms nominal time-out on power-up only from the por. the power- up timer operates on an internal rc oscillator. the chip is kept in reset as long as the pwrt is active. the pwrt?s time delay allows v dd to rise to an acceptable level. a configuration bit is provided to enable/disable the pwrt. the power-up time delay will vary from chip to chip due to v dd , temperature and process variation. see dc parameters for details (t pwrt , parameter #33). 11.6 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a delay of 1024 oscillator cycles (from osc1 input) after the pwrt delay is over (if pwrt is enabled). this helps to ensure that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp and hs modes and only on power-on reset or wake-up from sleep. 11.7 brown-out reset (bor) the configuration bit, boren, can enable or disable the brown-out reset circuit. if v dd falls below v bor (parameter d005, about 4v) for longer than t bor (parameter #35, about 100 s), the brown-out situation will reset the device. if v dd falls below v bor for less than t bor , a reset may not occur. once the brown-out occurs, the device will remain in brown-out reset until v dd rises above v bor . the power-up timer then keeps the device in reset for t pwrt (parameter #33, about 72 ms). if v dd should fall below v bor during t pwrt , the brown-out reset pro- cess will restart when v dd rises above v bor with the power-up timer reset. the power-up timer is always enabled when the brown-out reset circuit is enabled, regardless of the state of the pwrt configuration bit. 11.8 time-out sequence on power-up, the time-out sequence is as follows: the pwrt delay starts (if enabled) when a por reset occurs. then ost starts counting 1024 oscillator cycles when pwrt ends (lp, xt, hs). when the ost ends, the device comes out of reset. if mclr is kept low long enough, the time-outs will expire. bringing mclr high will begin execution imme- diately. this is useful for testing purposes or to synchro- nize more than one pic16f870/871 device operating in parallel. table 11-5 shows the reset conditions for the status, pcon and pc registers, while table 11-6 shows the reset conditions for all the registers. 11.9 power control/status register (pcon) the power control/status register, pcon, has up to two bits depending upon the device. bit0 is brown-out reset status bit, bor . bit bor is unknown on a power-on reset. it must then be set by the user and checked on subsequent resets to see if bit bor cleared, indicating a bor occurred. when the brown-out reset is disabled, the state of the bor bit is unpredictable and is, therefore, not valid at any time. bit1 is por (power-on reset status bit). it is cleared on a power-on reset and unaffected otherwise. the user must set this bit following a power-on reset. table 11-3: time-out in various situations oscillator configuration power-up brown-out wake-up from sleep pwrten = 0 pwrten = 1 xt, hs, lp 72 ms + 1024 t osc 1024 t osc 72 ms + 1024 t osc 1024 t osc rc 72 ms ? 72 ms ?
? 2003 microchip technology inc. ds30569b-page 93 pic16f870/871 table 11-4: status bits and their significance table 11-5: reset condition for special registers por bor to pd 0x11 power-on reset 0x0x illegal, to is set on por 0xx0 illegal, pd is set on por 1011 brown-out reset 1101 wdt reset 1100 wdt wake-up 11uu mclr reset during normal operation 1110 mclr reset during sleep or interrupt wake-up from sleep legend: x = don?t care, u = unchanged condition program counter status register pcon register power-on reset 000h 0001 1xxx ---- --0x mclr reset during normal operation 000h 000u uuuu ---- --uu mclr reset during sleep 000h 0001 0uuu ---- --uu wdt reset 000h 0000 1uuu ---- --uu wdt wake-up pc + 1 uuu0 0uuu ---- --uu brown-out reset 000h 0001 1uuu ---- --u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- --uu legend: u = unchanged, x = unknown, - = unimplemented bit, read as '0' note 1: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). table 11-6: initialization conditions for all registers register devices power-on reset, brown-out reset mclr resets wdt reset wake-up via wdt or interrupt w pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu indf pic16f870 pic16f871 n/a n/a n/a tmr0 pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu pcl pic16f870 pic16f871 0000h 0000h pc + 1 (2) status pic16f870 pic16f871 0001 1xxx 000q quuu (3) uuuq quuu (3) fsr pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu porta pic16f870 pic16f871 --0x 0000 --0u 0000 --uu uuuu portb pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu portc pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu portd pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu porte pic16f870 pic16f871 ---- -xxx ---- -uuu ---- -uuu pclath pic16f870 pic16f871 ---0 0000 ---0 0000 ---u uuuu intcon pic16f870 pic16f871 0000 000x 0000 000u uuuu uuuu (1) legend: u = unchanged, x = unknown, - = unimplemented bit, read as '0', q = value depends on condition, r = reserved, maintain clear note 1: one or more bits in intcon, pir1 and/or pir2 will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 3: see table 11-5 for reset value for specific condition.
pic16f870/871 ds30569b-page 94 ? 2003 microchip technology inc. pir1 pic16f870 pic16f871 r000 -000 r000 -000 ruuu -uuu (1) pic16f870 pic16f871 0000 -000 0000 -000 uuuu -uuu (1) pir2 pic16f870 pic16f871 ---0 ---- ---0 ---- ---u ---- (1) tmr1l pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu tmr1h pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu t1con pic16f870 pic16f871 --00 0000 --uu uuuu --uu uuuu tmr2 pic16f870 pic16f871 0000 0000 0000 0000 uuuu uuuu t2con pic16f870 pic16f871 -000 0000 -000 0000 -uuu uuuu ccpr1l pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu ccpr1h pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu ccp1con pic16f870 pic16f871 --00 0000 --00 0000 --uu uuuu rcsta pic16f870 pic16f871 0000 000x 0000 000x uuuu uuuu txreg pic16f870 pic16f871 0000 0000 0000 0000 uuuu uuuu rcreg pic16f870 pic16f871 0000 0000 0000 0000 uuuu uuuu adresh pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu adcon0 pic16f870 pic16f871 0000 00-0 0000 00-0 uuuu uu-u option_reg pic16f870 pic16f871 1111 1111 1111 1111 uuuu uuuu trisa pic16f870 pic16f871 --11 1111 --11 1111 --uu uuuu trisb pic16f870 pic16f871 1111 1111 1111 1111 uuuu uuuu trisc pic16f870 pic16f871 1111 1111 1111 1111 uuuu uuuu trisd pic16f870 pic16f871 1111 1111 1111 1111 uuuu uuuu trise pic16f870 pic16f871 0000 -111 0000 -111 uuuu -uuu pie1 pic16f870 pic16f871 r000 -000 r000 -000 ruuu -uuu pic16f870 pic16f871 0000 0000 0000 0000 uuuu uuuu pie2 pic16f870 pic16f871 ---0 ---- ---0 ---- ---u ---- pcon pic16f870 pic16f871 ---- --qq ---- --uu ---- --uu pr2 pic16f870 pic16f871 1111 1111 1111 1111 1111 1111 txsta pic16f870 pic16f871 0000 -010 0000 -010 uuuu -uuu spbrg pic16f870 pic16f871 0000 0000 0000 0000 uuuu uuuu adresl pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu adcon1 pic16f870 pic16f871 0--- 0000 0--- 0000 u--- uuuu eedata pic16f870 pic16f871 0--- 0000 0--- 0000 u--- uuuu eeadr pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu eedath pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu eeadrh pic16f870 pic16f871 xxxx xxxx uuuu uuuu uuuu uuuu eecon1 pic16f870 pic16f871 x--- x000 u--- u000 u--- uuuu eecon2 pic16f870 pic16f871 ---- ---- ---- ---- ---- ---- table 11-6: initialization condition s for all registers (continued) register devices power-on reset, brown-out reset mclr resets wdt reset wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as '0', q = value depends on condition, r = reserved, maintain clear note 1: one or more bits in intcon, pir1 and/or pir2 will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 3: see table 11-5 for reset value for specific condition.
? 2003 microchip technology inc. ds30569b-page 95 pic16f870/871 figure 11-5: time-out sequence on power-up (mclr tied to v dd ) figure 11-6: time-out sequence on power-up (mclr not tied to v dd ): case 1 figure 11-7: time-out sequence on power-up (mclr not tied to v dd ): case 2 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost
pic16f870/871 ds30569b-page 96 ? 2003 microchip technology inc. figure 11-8: slow rise time (mclr tied to v dd ) 11.10 interrupts the pic16f870/871 family has up to 14 sources of interrupt. the interrupt control register (intcon) records individual interrupt requests in flag bits. it also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>), enables (if set) all unmasked interrupts, or disables (if cleared) all interrupts. when bit gie is enabled, and an interrupt?s flag bit and mask bit are set, the interrupt will vector immediately. individual interrupts can be dis- abled through their corresponding enable bits in vari- ous registers. individual interrupt bits are set, regardless of the status of the gie bit. the gie bit is cleared on reset. the ?return from interrupt? instruction, retfie , exits the interrupt routine as well as sets the gie bit, which re-enables interrupts. the rb0/int pin interrupt, the rb port change interrupt, and the tmr0 overflow interrupt flags are contained in the intcon register. the peripheral interrupt flags are contained in the spe- cial function registers, pir1 and pir2. the correspond- ing interrupt enable bits are contained in special function registers, pie1 and pie2, and the peripheral interrupt enable bit is contained in special function register, intcon. when an interrupt is responded to, the gie bit is cleared to disable any further interrupt, the return address is pushed onto the stack and the pc is loaded with 0004h. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid recursive interrupts. for external interrupt events, such as the int pin or portb change interrupt, the interrupt latency will be three or four instruction cycles. the exact latency depends when the interrupt event occurs. the latency is the same for one or two-cycle instructions. individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, peie bit, or gie bit. v dd mclr internal por pwrt time-out ost time-out internal reset 0v 1v 5v t pwrt t ost note: individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, or the gie bit.
? 2003 microchip technology inc. ds30569b-page 97 pic16f870/871 figure 11-9: interrupt logic 11.10.1 int interrupt external interrupt on the rb0/int pin is edge triggered, either rising, if bit intedg (option_reg<6>) is set, or falling, if the intedg bit is clear. when a valid edge appears on the rb0/int pin, flag bit intf (intcon<1>) is set. this interrupt can be disabled by clearing enable bit inte (intcon<4>). flag bit intf must be cleared in software in the interrupt service routine before re-enabling this interrupt. the int inter- rupt can wake-up the processor from sleep, if bit inte was set prior to going into sleep. the status of global interrupt enable bit, gie, decides whether or not the processor branches to the interrupt vector following wake-up. see section 11.13 for details on sleep mode. 11.10.2 tmr0 interrupt an overflow (ffh 00h) in the tmr0 register will set flag bit t0if (intcon<2>). the interrupt can be enabled/disabled by setting/clearing enable bit t0ie (intcon<5>) (section 5.0). 11.10.3 portb intcon change an input change on portb<7:4> sets flag bit rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit rbie (intcon<4>) (section 4.2). pspif pspie adif adie rcif rcie txif txie ccp1if ccp1ie tmr2if tmr2ie tmr1if tmr1ie t0if t0ie intf inte rbif rbie gie peie wake-up (if in sleep mode) interrupt to cpu the following table shows which devices have which interrupts. device t0if intf rbif pspif adif rcif txif ccp1if tmr2if tmr1if eeif pic18f870 yes yes yes ? yes yes yes yes yes yes yes pic18f871 yes yes yes yes yes yes yes yes yes yes yes eeif eeie
pic16f870/871 ds30569b-page 98 ? 2003 microchip technology inc. 11.11 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key reg- isters during an interrupt, (i.e., w register and status register). this will have to be implemented in software. for the pic16f870/871 devices, the register w_temp must be defined in both banks 0 and 1 and must be defined at the same offset from the bank base address (i.e., if w_temp is defined at 0x20 in bank 0, it must also be defined at 0xa0 in bank 1). the registers, pclath_temp and status_temp, are only defined in bank 0. since the upper 16 bytes of each bank are common in the pic16f870/871 devices, temporary holding regis- ters w_temp, status_temp, and pclath_temp should be placed in here. these 16 locations don?t require banking and therefore, make it easier for con- text save and restore. the same code shown in example 11-1 can be used. example 11-1: saving status, w, and pclath registers in ram movwf w_temp ;copy w to temp register swapf status,w ;swap status to be saved into w clrf status ;bank 0, regardless of current bank, clears irp,rp1,rp0 movwf status_temp ;save status to bank zero status_temp register movf pclath, w ;only required if using pages 1, 2 and/or 3 movwf pclath_temp ;save pclath into w clrf pclath ;page zero, regardless of current page : :(isr) ;(insert user code here) : movf pclath_temp, w ;restore pclath movwf pclath ;move w into pclath swapf status_temp,w ;swap status_temp register into w ;(sets bank to original state) movwf status ;move w into status register swapf w_temp,f ;swap w_temp swapf w_temp,w ;swap w_temp into w
? 2003 microchip technology inc. ds30569b-page 99 pic16f870/871 11.12 watchdog timer (wdt) the watchdog timer is a free running on-chip rc oscil- lator which does not require any external components. this rc oscillator is separate from the rc oscillator of the osc1/clki pin. that means that the wdt will run, even if the clock on the osc1/clki and osc2/clko pins of the device has been stopped, for example, by execution of a sleep instruction. during normal operation, a wdt time-out generates a device reset (watchdog timer reset). if the device is in sleep mode, a wdt time-out causes the device to wake-up and continue with normal operation (watchdog timer wake-up). the to bit in the status register will be cleared upon a watchdog timer time-out. the wdt can be permanently disabled by clearing configuration bit wdten (section 11.1). wdt time-out period values may be found in the elec- trical specifications section under parameter #31. val- ues for the wdt prescaler (actually a postscaler, but shared with the timer0 prescaler) may be assigned using the option_reg register. figure 11-10: watchdog timer block diagram table 11-7: summary of watchdog timer registers note 1: the clrwdt and sleep instructions clear the wdt and the postscaler, if assigned to the wdt, and prevent it from timing out and generating a device reset condition. 2: when a clrwdt instruction is executed and the prescaler is assigned to the wdt, the prescaler count will be cleared, but the prescaler assignment is not changed. from tmr0 clock source (figure 5-1) to tmr0 (figure 5-1) postscaler wdt timer wdt enable bit 0 1 m u x psa 8 - to - 1 mux ps2:ps0 0 1 mux psa wdt time-out 8 note: psa and ps2:ps0 are bits in the option_reg register. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 2007h config. bits (1) boren (1) cp1 cp0 pwrten (1) wdten fosc1 fosc0 81h,181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 legend: shaded cells are not used by the watchdog timer. note 1: see register 11-1 for operation of these bits.
pic16f870/871 ds30569b-page 100 ? 2003 microchip technology inc. 11.13 power-down mode (sleep) power-down mode is entered by executing a sleep instruction. if enabled, the watchdog timer will be cleared but keeps running, the pd bit (status<3>) is cleared, the to (status<4>) bit is set, and the oscillator driver is turned off. the i/o ports maintain the status they had before the sleep instruction was executed (driving high, low, or hi-impedance). for lowest current consumption in this mode, place all i/o pins at either v dd or v ss , ensure no external cir- cuitry is drawing current from the i/o pin, power-down the a/d and disable external clocks. pull all i/o pins that are hi-impedance inputs, high or low externally, to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on-chip pull-ups on portb should also be considered. the mclr pin must be at a logic high level (v ihmc ). 11.13.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from int pin, rb port change or peripheral interrupt. external mclr reset will cause a device reset. all other events are considered a continuation of program execution and cause a ?wake-up?. the to and pd bits in the status register can be used to determine the cause of device reset. the pd bit, which is set on power-up, is cleared when sleep is invoked. the to bit is cleared if a wdt time-out occurred and caused wake-up. the following peripheral interrupts can wake the device from sleep: 1. psp read or write (pic16f874/877 only). 2. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 3. ccp capture mode interrupt. 4. special event trigger (timer1 in asynchronous mode using an external clock). 5. ssp (start/stop) bit detect interrupt. 6. ssp transmit or receive in slave mode (spi/i 2 c). 7. usart rx or tx (synchronous slave mode). 8. a/d conversion (when a/d clock source is rc). 9. eeprom write operation completion other peripherals cannot generate interrupts, since during sleep, no on-chip clocks are present. when the sleep instruction is being executed, the next instruction (pc + 1) is pre-fetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction and then branches to the inter- rupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. 11.13.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur:  if the interrupt occurs before the execution of a sleep instruction, the sleep instruction will com- plete as a nop . therefore, the wdt and wdt postscaler will not be cleared, the to bit will not be set and pd bits will not be cleared.  if the interrupt occurs during or after the execution of a sleep instruction, the device will immediately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt postscaler will be cleared, the to bit will be set and the pd bit will be cleared. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruction should be executed before a sleep instruction.
? 2003 microchip technology inc. ds30569b-page 101 pic16f870/871 figure 11-11: wake-up from sleep through interrupt 11.14 in-circuit debugger when the debug bit in the configuration word is pro- grammed to a '0', the in-circuit debugger functionality is enabled. this function allows simple debugging func- tions when used with mplab ? icd. when the micro- controller has this feature enabled, some of the resources are not available for general use. table 11-8 shows which features are consumed by the background debugger. table 11-8: debugger resources to use the in-circuit debugger function of the micro- controller, the design must implement in-circuit serial programming connections to mclr /v pp , v dd , gnd, rb7 and rb6. this will interface to the in-circuit debugger module available from microchip, or one of the third party development tool companies. 11.15 program verification/code protection if the code protection bit(s) have not been pro- grammed, the on-chip program memory can be read out for verification purposes. 11.16 id locations four memory locations (2000h - 2003h) are designated as id locations, where the user can store checksum or other code identification numbers. these locations are not accessible during normal execution, but are read- able and writable during program/verify. it is recom- mended that only the 4 least significant bits of the id location are used. q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clko (4) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc+1 pc+2 inst(pc) = sleep inst(pc - 1) inst(pc + 1) sleep processor in sleep interrupt latency (2) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle t ost (2) pc+2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024 t osc (drawing not to scale). this delay will not be there for rc osc mode. 3: gie = 1 assumed. in this case, after wake- up, the pr ocessor jumps to the interrupt routine. if gie = 0 , execution will continue in-line. 4: clko is not available in these osc modes, but shown here for timing reference. i/o pins rb6, rb7 stack 1 level program memory address 0000h must be nop last 100h words data memory 0x070 (0x0f0, 0x170, 0x1f0) 0x1eb - 0x1ef
pic16f870/871 ds30569b-page 102 ? 2003 microchip technology inc. 11.17 in-circuit serial programming pic16f870/871 microcontrollers can be serially pro- grammed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground, and the programming voltage. this allows customers to manufacture boards with unprogrammed devices, and then program the microcontroller just before shipping the product. this also allows the most recent firmware, or a custom firmware to be programmed. when using icsp, the part must be supplied at 4.5v to 5.5v, if a bulk erase will be executed. this includes reprogramming of the code protect, both from an on- state to off-state. for all other cases of icsp, the part may be programmed at the normal operating voltages. this means calibration values, unique user ids, or user code can be reprogrammed or added. for complete details of serial programming, please refer to the eeprom memory programming specification for the pic16f87x (ds39025). 11.18 low voltage icsp programming the lvp bit of the configuration word enables low volt- age icsp programming. this mode allows the micro- controller to be programmed via icsp, using a v dd source in the operating voltage range. this only means that v pp does not have to be brought to v ihh , but can instead be left at the normal operating voltage. in this mode, the rb3/pgm pin is dedicated to the program- ming function and ceases to be a general purpose i/o pin. during programming, v dd is applied to the mclr pin. to enter programming mode, v dd must be applied to the rb3/pgm pin, provided the lvp bit is set. the lvp bit defaults to on (?1?) from the factory. if low voltage programming mode is not used, the lvp bit can be programmed to a '0' and rb3/pgm becomes a digital i/o pin. however, the lvp bit may only be pro- grammed when programming is entered with v ihh on mclr . the lvp bit can only be charged when using high voltage on mclr . it should be noted, that once the lvp bit is programmed to 0, only the high voltage programming mode is avail- able and only high voltage programming mode can be used to program the device. when using low voltage icsp, the part must be supplied at 4.5v to 5.5v, if a bulk erase will be executed. this includes reprogramming of the code protect bits from an on-state to off-state. for all other cases of low voltage icsp, the part may be programmed at the normal oper- ating voltage. this means calibration values, unique user ids, or user code can be reprogrammed or added. note 1: the high voltage programming mode is always available, regardless of the state of the lvp bit, by applying v ihh to the mclr pin. 2: while in low voltage icsp mode, the rb3 pin can no longer be used as a general purpose i/o pin. 3: when using low voltage icsp program- ming (lvp) and the pull-ups on portb are enabled, bit 3 in the trisb register must be cleared to disable the pull-up on rb3 and ensure the proper operation of the device. 4: rb3 should not be allowed to float if lvp is enabled. an external pull-down device should be used to default the device to normal operating mode. if rb3 floats high, the pic16f870/871 devices will enter programming mode. 5: lvp mode is enabled by default on all devices shipped from microchip. it can be disabled by clearing the lvp bit in the config register. 6: disabling lvp will provide maximum compatibility to other pic16cxxx devices.
? 2003 microchip technology inc. ds30569b-page 103 pic16f870/871 12.0 instruction set summary each pic16f870/871 instruction is a 14-bit word, divided into an opcode, which specifies the instruc- tion type, and one or more operands, which further specify the operation of the instruction. the pic16f870/871 instruction set summary in table 12-2 lists byte-oriented , bit-oriented , and literal and con- trol operations. table 12-1 shows the opcode field descriptions. for byte-oriented instructions, 'f' represents a file reg- ister designator and 'd' represents a destination desig- nator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if 'd' is zero, the result is placed in the w register. if 'd' is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, 'b' represents a bit field designator which selects the number of the bit affected by the operation, while 'f' represents the address of the file in which the bit is located. for literal and control operations, 'k' represents an eight or eleven bit constant or literal value. table 12-1: opcode field descriptions the instruction set is highly orthogonal and is grouped into three basic categories:  byte-oriented operations  bit-oriented operations  literal and control operations all instructions are executed within one single instruc- tion cycle, unless a conditional test is true, or the pro- gram counter is changed as a result of an instruction. in this case, the execution takes two instruction cycles, with the second cycle executed as a nop . one instruc- tion cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. table 12-2 lists the instructions recognized by the mpasm tm assembler. figure 12-1 shows the general formats that the instructions can have. all examples use the following format to represent a hexadecimal number: 0xhh where h signifies a hexadecimal digit. figure 12-1: general format for instructions a description of each instruction is available in the picmicro? mid-range mcu family reference manual (ds33023). field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don't care location (= 0 or 1 ). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w, d = 1: store result in file register f. default is d = 1. pc program counter to time-out bit pd power-down bit note: to maintain upward compatibility with future pic16f870/871 products, do not use the option and tris instructions. byte-oriented file register operations 13 8 7 6 0 d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations 13 10 9 7 6 0 opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations 13 8 7 0 opcode k (literal) k = 8-bit immediate value 13 11 10 0 opcode k (literal) k = 11-bit immediate value general call and goto instructions only
pic16f870/871 ds30569b-page 104 ? 2003 microchip technology inc. table 12-2: pic16f870/871 instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f - f, d f, d f, d f, d f, d f, d f, d f - f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1(2) 1 1(2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c,dc,z z z z z z z z z c c c,dc,z z 1,2 1,2 2 1,2 1,2 1,2,3 1,2 1,2,3 1,2 1,2 1,2 1,2 1,2 1,2 1,2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1,2 1,2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k - k k k - k - - k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c,dc,z z to ,pd z to ,pd c,dc,z z note 1: when an i/o register is modified as a function of itself ( e.g., movf portb, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is '1' for a pin configured as input and is driven low by an external device, the data will be written back with a '0'. 2: if this instruction is executed on the tm r0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned to the timer0 module. 3: if program counter (pc) is modified, or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . note: additional information on the mid-range instruction set is available in the picmicro? mid-range mcu family reference manual (ds33023).
? 2003 microchip technology inc. ds30569b-page 105 pic16f870/871 12.1 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z description: the contents of the w register are added to the eight-bit literal 'k' and the result is placed in the w register. addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [0,1] operation: (w) + (f) (destination) status affected: c, dc, z description: add the contents of the w register with register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'. andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z description: the contents of w register are and?ed with the eight-bit literal 'k'. the result is placed in the w register. andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [0,1] operation: (w) .and. (f) (destination) status affected: z description: and the w register with register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none description: bit 'b' in register 'f' is cleared. bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none description: bit 'b' in register 'f' is set. btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none description: if bit 'b' in register 'f' is '0', the next instruction is executed. if bit 'b' is '1', then the next instruc- tion is discarded and a nop is executed instead, making this a 2t cy instruction. btfsc bit test, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none description: if bit 'b' in register 'f' is '1', the next instruction is executed. if bit 'b', in register 'f', is '0', the next instruction is discarded, and a nop is executed instead, making this a 2 t cy instruction.
pic16f870/871 ds30569b-page 106 ? 2003 microchip technology inc. call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc)+ 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none description: call subroutine. first, return address (pc+1) is pushed onto the stack. the eleven-bit immediate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f) 1 z status affected: z description: the contents of register 'f' are cleared and the z bit is set. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w) 1 z status affected: z description: w register is cleared. zero bit (z) is set. clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt 0 wdt prescaler, 1 to 1 pd status affected: to , pd description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [0,1] operation: (f ) (destination) status affected: z description: the contents of register 'f' are complemented. if 'd' is 0, the result is stored in w. if 'd' is 1, the result is stored back in register 'f'. decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (destination) status affected: z description: decrement register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'.
? 2003 microchip technology inc. ds30569b-page 107 pic16f870/871 decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (destination); skip if result = 0 status affected: none description: the contents of register 'f' are decremented. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. if the result is 1, the next instruc- tion is executed. if the result is 0, then a nop is executed instead making it a 2 t cy instruction. goto unconditional branch syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0> pclath<4:3> pc<12:11> status affected: none description: goto is an unconditional branch. the eleven-bit immediate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination) status affected: z description: the contents of register 'f' are incremented. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination), skip if result = 0 status affected: none description: the contents of register 'f' are incremented. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. if the result is 1, the next instruc- tion is executed. if the result is 0, a nop is executed instead, making it a 2 t cy instruction. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z description: the contents of the w register are or?ed with the eight bit literal 'k'. the result is placed in the w register. iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [0,1] operation: (w) .or. (f) (destination) status affected: z description: inclusive or the w register with register 'f'. if 'd' is 0 the result is placed in the w register. if 'd' is 1 the result is placed back in register 'f'.
pic16f870/871 ds30569b-page 108 ? 2003 microchip technology inc. movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [0,1] operation: (f) (destination) status affected: z description: the contents of register f are moved to a destination dependant upon the status of d. if d = 0, destination is w register. if d = 1, the destination is file register f itself. d = 1 is useful to test a file register, since status flag z is affected. movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none description: the eight-bit literal 'k' is loaded into w register. the don?t cares will assemble as 0?s. movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none description: move data from w register to register 'f'. nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none description: no operation. retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none description: the w register is loaded with the eight-bit literal 'k'. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction.
? 2003 microchip technology inc. ds30569b-page 109 pic16f870/871 rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register 'f' are rotated one bit to the left through the carry flag. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is stored back in register 'f'. return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction. rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register 'f' are rotated one bit to the right through the carry flag. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. register f c register f c sleep syntax: [ label ] sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd description: the power-down status bit, pd is cleared. time-out status bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. sublw subtract w from literal syntax: [ label ] sublw k operands: 0 k 255 operation: k - (w) ( w) status affected: c, dc, z description: the w register is subtracted (2?s complement method) from the eight-bit literal 'k'. the result is placed in the w register. subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [0,1] operation: (f) - (w) ( destination) status affected: c, dc, z description: subtract (2?s complement method) w register from register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'.
pic16f870/871 ds30569b-page 110 ? 2003 microchip technology inc. swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [0,1] operation: (f<3:0>) (destination<7:4>), (f<7:4>) (destination<3:0>) status affected: none description: the upper and lower nibbles of register 'f' are exchanged. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed in register 'f'. xorlw exclusive or literal with w syntax: [ label ]xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z description: the contents of the w register are xor?ed with the eight-bit literal 'k'. the result is placed in the w register. xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [0,1] operation: (w) .xor. (f) ( destination) status affected: z description: exclusive or the contents of the w register with register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'.
? 2003 microchip technology inc. ds30569b-page 111 pic16f870/871 13.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools:  integrated development environment - mplab ? ide software  assemblers/compilers/linkers - mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian - mplab c30 c compiler - mplab asm30 assembler/linker/library  simulators - mplab sim software simulator - mplab dspic30 software simulator emulators - mplab ice 2000 in-circuit emulator - mplab ice 4000 in-circuit emulator  in-circuit debugger - mplab icd 2  device programmers -pro mate ? ii universal device programmer - picstart ? plus development programmer  low cost demonstration boards - picdem tm 1 demonstration board - picdem.net tm demonstration board - picdem 2 plus demonstration board - picdem 3 demonstration board - picdem 4 demonstration board - picdem 17 demonstration board - picdem 18r demonstration board - picdem lin demonstration board - picdem usb demonstration board  evaluation kits -k ee l oq ? - picdem msc -microid ? -can - powersmart ? -analog 13.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? based application that contains:  an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately)  a full-featured editor with color coded context  a multiple project manager  customizable data windows with direct edit of contents  high level source code debugging  mouse over variable inspection  extensive on-line help the mplab ide allows you to:  edit your source files (either assembly or c)  one touch assemble (or compile) and download to picmicro emulator and simulator tools (automatically updates all project information)  debug using: - source files (assembly or c) - absolute listing file (mixed assembly and c) - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost effective simulators, through low cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increasing flexibility and power. 13.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all picmicro mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol ref- erence, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include:  integration into mplab ide projects  user defined macros to streamline assembly code  conditional assembly for multi-purpose source files  directives that allow complete control over the assembly process
pic16f870/871 ds30569b-page 112 ? 2003 microchip technology inc. 13.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi c compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 13.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can link relocatable objects from pre-compiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of pre-compiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include:  efficient linking of single libraries instead of many smaller files  enhanced code maintainability by grouping related modules together  flexible creation of libraries with easy module listing, replacement, deletion and extraction 13.5 mplab c30 c compiler the mplab c30 c compiler is a full-featured, ansi compliant, optimizing compiler that translates standard ansi c programs into dspic30f assembly language source. the compiler also supports many command- line options and language extensions to take full advantage of the dspic30f device hardware capabili- ties, and afford fine control of the compiler code generator. mplab c30 is distributed with a complete ansi c standard library. all library functions have been vali- dated and conform to the ansi c library standard. the library includes functions for string manipulation, dynamic memory allocation, data conversion, time- keeping, and math functions (trigonometric, exponen- tial and hyperbolic). the compiler provides symbolic information for high level source debugging with the mplab ide. 13.6 mplab asm30 assembler, linker, and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 compiler uses the assembler to produce it?s object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include:  support for the entire dspic30f instruction set  support for fixed-point and floating-point data  command line interface  rich directive set  flexible macro language  mplab ide compatibility 13.7 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any pin. the execu- tion can be performed in single-step, execute until break, or trace mode. the mplab sim simulator fully supports symbolic debugging using the mplab c17 and mplab c18 c compilers, as well as the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent, economical software development tool. 13.8 mplab sim30 software simulator the mplab sim30 software simulator allows code development in a pc hosted environment by simulating the dspic30f series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any of the pins. the mplab sim30 simulator fully supports symbolic debugging using the mplab c30 c compiler and mplab asm30 assembler. the simulator runs in either a command line mode for automated tasks, or from mplab ide. this high speed simulator is designed to debug, analyze and optimize time intensive dsp routines.
? 2003 microchip technology inc. ds30569b-page 113 pic16f870/871 13.9 mplab ice 2000 high performance universal in-circuit emulator the mplab ice 2000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator sys- tem with enhanced trace, trigger and data monitoring features. interchangeable processor modules allow the system to be easily reconfigured for emulation of differ- ent processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 13.10 mplab ice 4000 high performance universal in-circuit emulator the mplab ice 4000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for high- end picmicro microcontrollers. software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab icd 4000 is a premium emulator system, providing the features of mplab ice 2000, but with increased emulation memory and high speed perfor- mance for dspic30f and pic18xxxx devices. its advanced emulator features include complex triggering and timing, up to 2 mb of emulation memory, and the ability to view variables in real-time. the mplab ice 4000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft windows 32-bit operating system were cho- sen to best make these features available in a simple, unified application. 13.11 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low cost, run-time development tool, connecting to the host pc via an rs-232 or high speed usb interface. this tool is based on the flash picmicro mcus and can be used to develop for these and other picmicro microcontrollers. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost effective in-circuit flash debug- ging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single-stepping and watching variables, cpu status and peripheral registers. running at full speed enables testing hardware and applications in real-time. mplab icd 2 also serves as a development programmer for selected picmicro devices. 13.12 pro mate ii universal device programmer the pro mate ii is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features an lcd display for instructions and error messages and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify, and program picmicro devices without a pc connection. it can also set code protection in this mode. 13.13 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most picmicro devices up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant.
pic16f870/871 ds30569b-page 114 ? 2003 microchip technology inc. 13.14 picdem 1 picmicro demonstration board the picdem 1 demonstration board demonstrates the capabilities of the pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the sample microcontrollers provided with the picdem 1 demonstration board can be programmed with a pro mate ii device program- mer, or a picstart plus development programmer. the picdem 1 demonstration board can be connected to the mplab ice in-circuit emulator for testing. a pro- totype area extends the circuitry for additional applica- tion components. features include an rs-232 interface, a potentiometer for simulated analog input, push button switches and eight leds. 13.15 picdem.net internet/ethernet demonstration board the picdem.net demonstration board is an internet/ ethernet demonstration board using the pic18f452 microcontroller and tcp/ip firmware. the board supports any 40-pin dip device that conforms to the standard pinout used by the pic16f877 or pic18c452. this kit features a user friendly tcp/ip stack, web server with html, a 24l256 serial eeprom for xmodem download to web pages into serial eeprom, icsp/mplab icd 2 interface con- nector, an ethernet interface, rs-232 interface, and a 16 x 2 lcd display. also included is the book and cd-rom ?tcp/ip lean, web servers for embedded systems,? by jeremy bentham 13.16 picdem 2 plus demonstration board the picdem 2 plus demonstration board supports many 18-, 28-, and 40-pin microcontrollers, including pic16f87x and pic18fxx2 devices. all the neces- sary hardware and software is included to run the dem- onstration programs. the sample microcontrollers provided with the picdem 2 demonstration board can be programmed with a pro mate ii device program- mer, picstart plus development programmer, or mplab icd 2 with a universal programmer adapter. the mplab icd 2 and mplab ice in-circuit emulators may also be used with the picdem 2 demonstration board to test firmware. a prototype area extends the circuitry for additional application components. some of the features include an rs-232 interface, a 2 x 16 lcd display, a piezo speaker, an on-board temperature sensor, four leds, and sample pic18f452 and pic16f877 flash microcontrollers. 13.17 picdem 3 pic16c92x demonstration board the picdem 3 demonstration board supports the pic16c923 and pic16c924 in the plcc package. all the necessary hardware and software is included to run the demonstration programs. 13.18 picdem 4 8/14/18-pin demonstration board the picdem 4 can be used to demonstrate the capa- bilities of the 8-, 14-, and 18-pin pic16xxxx and pic18xxxx mcus, including the pic16f818/819, pic16f87/88, pic16f62xa and the pic18f1320 fam- ily of microcontrollers. picdem 4 is intended to show- case the many features of these low pin count parts, including lin and motor control using eccp. special provisions are made for low power operation with the supercapacitor circuit, and jumpers allow on-board hardware to be disabled to eliminate current draw in this mode. included on the demo board are provisions for crystal, rc or canned oscillator modes, a five volt regulator for use with a nine volt wall adapter or battery, db-9 rs-232 interface, icd connector for program- ming via icsp and development with mplab icd 2, 2x16 liquid crystal display, pcb footprints for h-bridge motor driver, lin transceiver and eeprom. also included are: header for expansion, eight leds, four potentiometers, three push buttons and a prototyping area. included with the kit is a pic16f627a and a pic18f1320. tutorial firmware is included along with the user?s guide. 13.19 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. a pro- grammed sample is included. the pro mate ii device programmer, or the picstart plus development pro- grammer, can be used to reprogram the device for user tailored application development. the picdem 17 demonstration board supports program download and execution from external on-board flash memory. a generous prototype area is available for user hardware expansion.
? 2003 microchip technology inc. ds30569b-page 115 pic16f870/871 13.20 picdem 18r pic18c601/801 demonstration board the picdem 18r demonstration board serves to assist development of the pic18c601/801 family of microchip microcontrollers. it provides hardware implementation of both 8-bit multiplexed/de-multiplexed and 16-bit memory modes. the board includes 2 mb external flash memory and 128 kb sram memory, as well as serial eeprom, allowing access to the wide range of memory types supported by the pic18c601/801. 13.21 picdem lin pic16c43x demonstration board the powerful lin hardware and software kit includes a series of boards and three picmicro microcontrollers. the small footprint pic16c432 and pic16c433 are used as slaves in the lin communication and feature on-board lin transceivers. a pic16f874 flash microcontroller serves as the master. all three micro- controllers are programmed with firmware to provide lin bus communication. 13.22 pickit tm 1 flash starter kit a complete "development system in a box", the pickit flash starter kit includes a convenient multi-section board for programming, evaluation, and development of 8/14-pin flash pic ? microcontrollers. powered via usb, the board operates under a simple windows gui. the pickit 1 starter kit includes the user's guide (on cd rom), pickit 1 tutorial software and code for vari- ous applications. also included are mplab ? ide (inte- grated development environment) software, software and hardware "tips 'n tricks for 8-pin flash pic ? microcontrollers" handbook and a usb interface cable. supports all current 8/14-pin flash pic microcontrollers, as well as many future planned devices. 13.23 picdem usb pic16c7x5 demonstration board the picdem usb demonstration board shows off the capabilities of the pic16c745 and pic16c765 usb microcontrollers. this board provides the basis for future usb products. 13.24 evaluation and programming tools in addition to the picdem series of circuits, microchip has a line of evaluation kits and demonstration software for these products. k ee l oq evaluation and programming tools for microchip?s hcs secure data products  can developers kit for automotive network applications  analog design boards and filter design software  powersmart battery charging evaluation/ calibration kits irda ? development kit  microid development and rflab tm development software  seeval ? designer kit for memory evaluation and endurance calculations  picdem msc demo boards for switching mode power supply, high power ir driver, delta sigma adc, and flow rate sensor check the microchip web page and the latest product line card for the complete list of demonstration and evaluation kits.
pic16f870/871 ds30569b-page 116 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 117 pic16f870/871 14.0 electrical characteristics absolute maximum ratings ? ambient temperature under bias................................................................................................. ............... .-55 to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any pin with respect to v ss (except v dd , mclr . and ra4) ......................................... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss ............................................................................................................ -0.3 to +7.5v voltage on mclr with respect to v ss (note 2) ............................................................................................0 to +13.25v voltage on ra4 with respect to vss ............................................................................................. .....................0 to +8.5v total power dissipation (note 1) ............................................................................................................................... 1.0w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ..................................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) ............................................................................................................. 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by porta, portb, and porte (combined) (note 3) ...................................................200 ma maximum current sourced by porta, portb, and porte (combined) (note 3) ..............................................200 ma maximum current sunk by portc and portd (combined) (note 3) .................................................................200 ma maximum current sourced by portc and portd (combined) (note 3) ............................................................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd - i oh } + {(v dd - v oh ) x i oh } + (v o l x i ol ) 2: voltage spikes below v ss at the mclr pin, inducing currents greater than 80 ma, may cause latch-up. thus, a series resistor of 50-100 ? should be used when applying a ?low? level to the mclr pin, rather than pulling this pin directly to v ss . 3: portd and porte are not implemented on the 28-pin devices. ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic16f870/871 ds30569b-page 118 ? 2003 microchip technology inc. figure 14-1: pic16fxxx voltage-frequency graph figure 14-2: pic16lfxxx voltage-frequency graph frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 20 mhz 5.0v 3.5v 3.0v 2.5v frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 5.0v 3.5v 3.0v 2.5v equation 1: f max = (6.0 mhz/v) (v ddappmin ? 2.0v) + 4 mhz; v ddappmin = 2.0v - 3.0v note 1: v ddappmin is the minimum voltage of the picmicro ? device in the application. 4 mhz 10 mhz note 2: f max has a maximum frequency of 10 mhz. 20 mhz e q u a t i o n 1 e q u a t i o n 2 equation 2: f max = (10.0 mhz/v) (v ddappmin ? 3.0v) + 10 mhz; v ddappmin = 3.0v - 4.0v
? 2003 microchip technology inc. ds30569b-page 119 pic16f870/871 14.1 dc characteristics: pic16f870/871 (industrial, extended) pic16lf870/871 (commercial, industrial) pic16lf870/871 (commercial, industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial pic16f870/871 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions v dd supply voltage d001 pic16lf870/871 2.0 ? 5.5 v all configurations. see figure 14-2 for details. d001 d001a pic16f870/871 4.0 v bor * v bor ? ? ? 5.5 5.5 5.5 v v v all configurations. bor enabled, f max = 14 mhz (note 7) , -40c to +85c bor enabled, f max = 10 mhz (note 7) , -40c to +125c d002* v dr ram data retention voltage (1) ?1.5?v d003 v por v dd start voltage to ensure internal power-on reset signal ? vss ? v see section on power-on reset for details d004* sv dd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section on power-on reset for details d005 v bor brown-out reset voltage 3.7 4.0 4.35 v boren bit in configuration word enabled * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered without losing ram data. 2: the supply current is mainly a function of the operating voltage and frequency. other factors such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail to rail; all i/o pins tri-stated, pulled to v dd mclr = v dd ; wdt enabled/disabled as specified. 3: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in hi-impedance state and tied to v dd and v ss . 4: for rc osc configuration, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 5: timer1 oscillator (when enabled) adds approximately 20 a to the specification. this value is from characterization and is for design guidance only. this is not tested. 6: the ? current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. 7: when bor is enabled, the device will operate correctly until the v bor voltage trip point is reached.
pic16f870/871 ds30569b-page 120 ? 2003 microchip technology inc. i dd supply current (2,5) d010 d010a pic16lf870/871 ? ? 0.6 20 2.0 35 ma a xt, rc osc configuration f osc = 4 mhz, v dd = 3.0v (note 4) lp osc configuration f osc = 32 khz, v dd = 3.0v, wdt disabled d010 d013 pic16f870/871 ? ? ? 1.6 7 7 4 15 15 ma ma ma xt, rc osc configuration f osc = 4 mhz, v dd = 5.5v (note 4) hs osc configuration f osc = 20 mhz, v dd = 5.5v, -40 c to +85 c hs osc configuration f osc = 10 mhz, v dd = 5.5v, -40 c to +125 c d015* ? i bor brown-out reset current (6) ?85200 a bor enabled, v dd = 5.0v i pd power-down current (3,5) d020 d021 d021a pic16lf870/871 ? ? ? 7.5 0.8 0.9 30 4.5 5 a a a v dd = 3.0v, wdt enabled, -40 c to +85 c v dd = 3.0v, wdt disabled, 0 c to +70 c v dd = 3.0v, wdt disabled, -40 c to +85 c d020 d20a d021 d021a d21b pic16f870/871 ? ? ? ? ? 10.5 10.5 1.5 1.5 1.5 42 60 16 19 30 a a a a a v dd = 4.0v, wdt enabled, -40 c to +85 c v dd = 4.0v, wdt enabled, -40 c to +125 c v dd = 4.0v, wdt disabled, -0 c to +70 c v dd = 4.0v, wdt disabled, -40 c to +85 c v dd = 4.0v, wdt disabled, -40 c to +125 c d023* ? i bor brown-out reset current (6) ?85200 a bor enabled, v dd = 5.0v 14.1 dc characteristics: pic16f870/871 (industrial, extended) pic16lf870/871 (commercial, industrial) (continued) pic16lf870/871 (commercial, industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial pic16f870/871 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered without losing ram data. 2: the supply current is mainly a function of the operating voltage and frequency. other factors such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail to rail; all i/o pins tri-stated, pulled to v dd mclr = v dd ; wdt enabled/disabled as specified. 3: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in hi-impedance state and tied to v dd and v ss . 4: for rc osc configuration, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 5: timer1 oscillator (when enabled) adds approximately 20 a to the specification. this value is from characterization and is for design guidance only. this is not tested. 6: the ? current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. 7: when bor is enabled, the device will operate correctly until the v bor voltage trip point is reached.
? 2003 microchip technology inc. ds30569b-page 121 pic16f870/871 14.2 dc characteristics: pic16f870/871 (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial operating voltage v dd range as described in dc spec section 14.1 and section 14.2. param no. sym characteristic min typ? max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss ? 0.15 v dd v for entire v dd range d030a v ss ?0.8v v4.5v v dd 5.5v d031 with schmitt trigger buffer v ss ?0.2 v dd v d032 mclr , osc1 (in rc mode) v ss ?0.2 v dd v d033 osc1 (in xt, hs and lp) v ss ?0.3 v dd v (note 1) ports rc3 and rc4: d034 with schmitt trigger buffer v ss ?0.3 v dd v for entire v dd range d034a with smbus -0.5 ? 0.6 v for v dd = 4.5 to 5.5v v ih input high voltage i/o ports: ? d040 with ttl buffer 2.0 ? v dd v4.5v v dd 5.5v d040a 0.25 v dd + 0.8v ?v dd v for entire v dd range d041 with schmitt trigger buffer 0.8 v dd ?v dd v for entire v dd range d042 mclr 0.8 v dd ?v dd v d042a osc1 (xt, hs and lp) 0.7 v dd ?v dd v (note 1) d043 osc1 (in rc mode) 0.9 v dd ?v dd v ports rc3 and rc4: d044 with schmitt trigger buffer 0.7 v dd ?v dd v for entire v dd range d044a with smbus 1.4 ? 5.5 v for v dd = 4.5 to 5.5v d070 i purb portb weak pull-up current 50 250 400 av dd = 5v, v pin = v ss i il input leakage current (notes 2, 3) d060 i/o ports ? ? 1 avss v pin v dd , pin at hi-impedance d061 mclr , ra4/t0cki ? ? 5 avss v pin v dd d063 osc1 ? ? 5 avss v pin v dd , xt, hs and lp osc configuration * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the pic16f870/871 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
pic16f870/871 ds30569b-page 122 ? 2003 microchip technology inc. v ol output low voltage d080 i/o ports ? ? 0.6 v i ol = 8.5 ma, v dd = 4.5v, -40 c to +85 c d083 osc2/clko (rc osc config) ? ? 0.6 v i ol = 1.6 ma, v dd = 4.5v, -40 c to +85 c v oh output high voltage d090 i/o ports (note 3) v dd ? 0.7 ? ? v i oh = -3.0 ma, v dd = 4.5v, -40 c to +85 c d092 osc2/clko (rc osc config) v dd ? 0.7 ? ? v i oh = -1.3 ma, v dd = 4.5v, -40 c to +85 c d150* v od open drain high voltage ? ? 8.5 v ra4 pin capacitive loading specs on output pins d100 c osc2 osc2 pin ? ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1. d101 d102 c io c b all i/o pins and osc2 (in rc mode) scl, sda in i 2 c mode ? ? ? ? 50 400 pf pf data eeprom memory d120 e d endurance 100k ? ? e/w 25 c at 5v d121 v drw v dd for read/write v min ? 5.5 v using eecon to read/write v min = min operating voltage d122 t dew erase/write cycle time ? 4 8 ms program flash memory d130 e p endurance 1000 ? ? e/w 25 c at 5v d131 v pr v dd for read v min ?5.5 vv min = min operating voltage d132a v dd for erase/write v min ? 5.5 v using eecon to read/write, v min = min operating voltage d133 t pew erase/write cycle time ? 4 8 ms 14.2 dc characteristics: pic16f870/871 (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial operating voltage v dd range as described in dc spec section 14.1 and section 14.2. param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the pic16f870/871 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
? 2003 microchip technology inc. ds30569b-page 123 pic16f870/871 14.3 dc characteristics: pic16f870/871 (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c operating voltage v dd range as described in dc specification (section ) param no. sym characteristic min typ? max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss ?0.15 v dd v for entire v dd range d030a v ss ?0.8v v4.5v v dd 5.5v d031 with schmitt trigger buffer v ss ?0.2 v dd v d032 mclr , osc1 (in rc mode) v ss ?0.2 v dd v d033 osc1 (in xt, hs and lp) v ss ?0.3 v dd v (note 1) ports rc3 and rc4: d034 with schmitt trigger buffer v ss ?0.3 v dd v for entire v dd range d034a with smbus -0.5 ? 0.6 v for v dd = 4.5 to 5.5v v ih input high voltage i/o ports: ? d040 with ttl buffer 2.0 ? v dd v4.5v v dd 5.5v d040a 0.25 v dd + 0.8v ?v dd v for entire v dd range d041 with schmitt trigger buffer 0.8 v dd ?v dd v for entire v dd range d042 mclr 0.8 v dd ?v dd v d042a osc1 (xt, hs and lp) 0.7 v dd ?v dd v (note 1) d043 osc1 (in rc mode) 0.9 v dd ?v dd v ports rc3 and rc4: d044 with schmitt trigger buffer 0.7 v dd ?v dd v for entire v dd range d044a with smbus 1.4 ? 5.5 v for v dd = 4.5 to 5.5v d070a i purb portb weak pull-up current 50 250 400 av dd = 5v, v pin = v ss i il input leakage current (2,3) d060 i/o ports ? ? 1 avss v pin v dd , pin at hi-impedance d061 mclr , ra4/t0cki ? ? 5 avss v pin v dd d063 osc1 ? ? 5 avss v pin v dd , xt, hs and lp osc configuration * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the pic16f87x be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
pic16f870/871 ds30569b-page 124 ? 2003 microchip technology inc. v ol output low voltage d080a i/o ports ? ? 0.6 v i ol = 7.0 ma, v dd = 4.5v d083a osc2/clko (rc osc config) ? ? 0.6 v i ol = 1.2 ma, v dd = 4.5v v oh output high voltage d090a i/o ports (3) v dd ? 0.7 ? ? v i oh = -2.5 ma, v dd = 4.5v d092a osc2/clko (rc osc config) v dd ? 0.7 ? ? v i oh = -1.0 ma, v dd = 4.5v d150* v od open drain high voltage ? ? 8.5 v ra4 pin capacitive loading specs on output pins d100 c osc2 osc2 pin ? ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 d102 c io c b all i/o pins and osc2 (rc mode) scl, sda (i 2 c mode) ? ? ? ? 50 400 pf pf data eeprom memory d120 e d endurance 100k ? ? e/w 25 c at 5v d121 v drw v dd for read/write v min ? 5.5 v using eecon to read/write, v min = min. operating voltage d122 t dew erase/write cycle time ? 4 8 ms program flash memory d130 e p endurance 1000 ? ? e/w 25 c at 5v d131 v pr v dd for read v min ?5.5 vv min = min operating voltage d132a v dd for erase/write v min ? 5.5 v using eecon to read/write, v min = min. operating voltage d133 t pew erase/write cycle time ? 4 8 ms 14.3 dc characteristics: pic16f870/871 (extended) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c operating voltage v dd range as described in dc specification (section ) param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the pic16f87x be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
? 2003 microchip technology inc. ds30569b-page 125 pic16f870/871 14.4 timing parameter symbology the timing parameter symbols have been created following one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s ffall pperiod hhigh rrise i invalid (hi-impedance) v valid l low z hi-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
pic16f870/871 ds30569b-page 126 ? 2003 microchip technology inc. figure 14-3: load conditions figure 14-4: external clock timing v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osc2, but including portd and porte outputs as ports 15 pf for osc2 output note: portd and porte are not implemented on the pic16f870. load condition 1 load condition 2 osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4
? 2003 microchip technology inc. ds30569b-page 127 pic16f870/871 table 14-1: external clock timing requirements param no. sym characteristic min typ? max units conditions f osc external clki frequency (note 1) dc ? 4 mhz xt and rc osc mode dc ? 4 mhz hs osc mode (-04) dc ? 20 mhz hs osc mode (-20) dc ? 200 khz lp osc mode oscillator frequency (note 1) dc ? 4 mhz rc osc mode 0.1 ? 4 mhz xt osc mode 4 5 ? ? 20 200 mhz khz hs osc mode lp osc mode 1 t osc external clki period (note 1) 250 ? ? ns xt and rc osc mode 250 ? ? ns hs osc mode (-04) 50 ? ? ns hs osc mode (-20) 5? ? s lp osc mode oscillator period (note 1) 250 ? ? ns rc osc mode 250 ? 10,000 ns xt osc mode 250 ? 250 ns hs osc mode (-04) 50 ? 250 ns hs osc mode (-20) 5? ? s lp osc mode 2 t cy instruction cycle time (note 1) 200 t cy dc ns t cy = 4/f osc 3 to s l , to s h external clock in (osc1) high or low time 100 ? ? ns xt oscillator 2.5 ? ? s lp oscillator 15 ? ? ns hs oscillator 4 to s r , to s f external clock in (osc1) rise or fall time ? ? 25 ns xt oscillator ? ? 50 ns lp oscillator ? ? 15 ns hs oscillator ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator oper- ation and/or higher than expected current consumption. all devices are tested to operate at "min." values with an external clock applied to the osc1/clki pin. when an external clock input is used, the "max." cycle time limit is "dc" (no clock) for all devices.
pic16f870/871 ds30569b-page 128 ? 2003 microchip technology inc. figure 14-5: clko and i/o timing table 14-2: clko and i/o timing requirements note: refer to figure 14-3 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value param no. sym characteristic min typ? max units conditions 10* tosh2ckl osc1 to clko ? 75 200 ns (note 1) 11* tosh2ckh osc1 to clko ? 75 200 ns (note 1) 12* tckr clko rise time ? 35 100 ns (note 1) 13* tckf clko fall time ? 35 100 ns (note 1) 14* tckl2iov clko to port out valid ? ? 0.5 t cy + 20 ns (note 1) 15* tiov2ckh port in valid before clko t osc + 200 ? ? ns (note 1) 16* tckh2ioi port in hold after clko 0??ns (note 1) 17* tosh2iov osc1 (q1 cycle) to port out valid ? 100 255 ns 18* tosh2ioi osc1 (q2 cycle) to port input invalid (i/o in hold time) standard ( f ) 100 ? ? ns extended ( lf ) 200 ? ? ns 19* tiov2osh port input valid to osc1 (i/o in setup time) 0 ? ? ns 20* t io r port output rise time standard ( f ) ? 10 40 ns extended ( lf ) ? ? 145 ns 21* t io f port output fall time standard ( f ) ? 10 40 ns extended ( lf ) ? ? 145 ns 22??* t inp int pin high or low time t cy ??ns 23??* t rbp rb7:rb4 change int high or low time t cy ??ns * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless other wise stated. these parameters are for design guidance only and are not tested. ?? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in rc mode where clko output is 4 x t osc .
? 2003 microchip technology inc. ds30569b-page 129 pic16f870/871 figure 14-6: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 14-7: brown-out reset timing table 14-3: reset, watchdog timer, oscillator start-up timer, power-up timer, and brown-out reset requirements param no. sym characteristic min typ? max units conditions 30 tmcl mclr pulse width (low) 2 ? ? sv dd = 5v, -40c to +85c 31* t wdt watchdog timer time-out period (no prescaler) 71833msv dd = 5v, -40c to +85c 32 t ost oscillation start-up timer period ? 1024 t osc ??t osc = osc1 period 33* t pwrt power up timer period 28 72 132 ms v dd = 5v, -40c to +85c 34 t ioz i/o hi-impedance from mclr low or watchdog timer reset ??2.1 s 35 t bor brown-out reset pulse width 100 ? ? sv dd v bor (d005) * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. v dd mclr internal por pwrt time-out osc time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 14-3 for load conditions. v dd v bor 35
pic16f870/871 ds30569b-page 130 ? 2003 microchip technology inc. figure 14-8: timer0 and timer1 external clock timings table 14-4: timer0 and timer1 external clock requirements param no. sym characteristic min typ? max units conditions 40* tt0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ? ns must also meet parameter 42 with prescaler 10 ? ? ns 41* tt0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ? ns must also meet parameter 42 with prescaler 10 ? ? ns 42* tt0p t0cki period no prescaler t cy + 40 ? ? ns with prescaler greater of: 20 or t cy + 40 n ? ? ns n = prescale value (2, 4, ..., 256) 45* tt1h t1cki high time synchronous, prescaler = 1 0.5 t cy + 20 ? ? ns must also meet parameter 47 synchronous, prescaler = 2,4,8 standard( f )15??ns extended( lf )25??ns asynchronous standard( f )30??ns extended( lf )50??ns 46* tt1l t1cki low time synchronous, prescaler = 1 0.5 t cy + 20 ? ? ns must also meet parameter 47 synchronous, prescaler = 2,4,8 standard( f )15??ns extended( lf )25??ns asynchronous standard( f )30??ns extended( lf )50??ns 47* tt1p t1cki input period synchronous standard( f ) greater of : 30 or t cy + 40 n ? ? ns n = prescale value (1, 2, 4, 8) extended( lf ) greater of : 50 or t cy + 40 n n = prescale value (1, 2, 4, 8) asynchronous standard( f )60??ns extended( lf ) 100 ? ? ns ft1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) dc ? 200 khz 48 tckeztmr1 delay from external clock edge to timer increment 2 t osc ?7 t osc ? * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 14-3 for load conditions. 46 47 45 48 41 42 40 ra4/t0cki rc0/t1oso/t1cki tmr0 or tmr1
? 2003 microchip technology inc. ds30569b-page 131 pic16f870/871 figure 14-9: capture/compare/pwm timings (ccp1) table 14-5: capture/compare/pwm requirements (ccp1) note: refer to figure 14-3 for load conditions. rc2/ccp1 (capture mode) 50 51 52 53 54 rc2/ccp1 (compare or pwm mode) param no. sym characteristic min typ? max units conditions 50* tccl * ccp1 input low time no prescaler 0.5 t cy + 20 ? ? ns with prescaler standard( f )10??ns extended( lf )20??ns 51* tcch ccp1 input high time no prescaler 0.5 t cy + 20 ? ? ns with prescaler standard( f )10??ns extended( lf )20??ns 52* tccp ccp1 input period 3 t cy + 40 n ? ? ns n = prescale value (1,4 or 16) 53* tccr ccp1 output rise time standard( f ) ? 10 25 ns extended( lf ) ? 25 50 ns 54* tccf ccp1 output fall time standard( f ) ? 10 25 ns extended( lf ) ? 25 45 ns * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested.
pic16f870/871 ds30569b-page 132 ? 2003 microchip technology inc. figure 14-10: parallel slave port timing (pic16f871 only) table 14-6: parallel slave port requirements (pic16f871 only) note: refer to figure 14-3 for load conditions. re2/cs re0/rd re1/wr rd7:rd0 62 63 64 65 param no. sym characteristic min typ? max units conditions 62 tdtv2wrh data in valid before wr or cs (setup time) 20 25 ? ? ? ? ns ns extended range only 63* twrh2dti wr or cs to data?in invalid (hold time) standard( f )20??ns extended( lf )35 ? ? ns 64 trdl2dtv rd and cs to data?out valid ? ? ? ? 80 90 ns ns extended range only 65 trdh2dti rd or cs to data?out invalid 10 ? 30 ns * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested.
? 2003 microchip technology inc. ds30569b-page 133 pic16f870/871 figure 14-11: usart synchronous transmission (master/slave) timing table 14-7: usart synchronous transmission requirements figure 14-12: usart synchronous receive (master/slave) timing table 14-8: usart synchronous receive requirements note: refer to figure 14-3 for load conditions. 121 121 122 rc6/tx/ck rc7/rx/dt pin pin 120 param no. sym characteristic min typ? max units conditions 120 tckh2dtv sync xmit (master & slave) clock high to data out valid standard( f ) ? ? 80 ns extended( lf ) ? ? 100 ns 121 tckrf clock out rise time and fall time (master mode) standard( f )??45ns extended( lf )??50ns 122 tdtrf data out rise time and fall time standard( f )??45ns extended( lf )??50ns ? data in ?typ? column is at 5v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 14-3 for load conditions. 125 126 rc6/tx/ck rc7/rx/dt pin pin param no. sym characteristic min typ? max units conditions 125 tdtv2ckl sync rcv (master & slave) data setup before ck (dt setup time) 15 ? ? ns 126 tckl2dtl data hold after ck (dt hold time) 15 ? ? ns ? data in ?typ? column is at 5v, 25 c unless otherwise stated. these parameter s are for design guidance only and are not tested.
pic16f870/871 ds30569b-page 134 ? 2003 microchip technology inc. table 14-9: pic16f870/871 (industrial) pic16lf870/871 (industrial) param no. sym characteristic min typ? max units conditions a01 n r resolution ? ? 10-bits bit v ref = v dd = 5.12v, v ss v ain v ref a03 e il integral linearity error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a04 e dl differential linearity error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a06 e off offset error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a07 e gn gain error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a10 ? monotonicity (3) ? guaranteed ? ? v ss v ain v ref a20 v ref reference voltage (v ref + ? v ref -) 2.0v ? v dd + 0.3 v a21 v ref + reference voltage high v dd ? 2.5v v dd + 0.3v v must meet spec. a20 a22 v ref - reference voltage low v ss ? 0.3v v ref + ? 2.0v v must meet spec. a20 a25 v ain analog input voltage v ss ? 0.3 ? v ref + 0.3 v a30 z ain recommended impedance of analog voltage source ??10.0k ? a40 i ad a/d conversion current (v dd ) standard( f ) ? 220 ? a average current consumption when a/d is on (note 1) . extended( lf )? 90 ? a a50 i ref v ref input current (note 2) 10 ? ? ? 1000 10 a a during v ain acquisition. based on differential of v hold to v ain to charge c hold , see section 10.1. during a/d conversion cycle * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: when a/d is off, it will not consume any current other than minor leakage current. the power-down current spec includes any such leakage from the a/d module. 2: v ref current is from ra3 pin or v dd pin, whichever is selected as reference input. 3: the a/d conversion result never dec reases with an increase in the i nput voltage, and has no missing codes.
? 2003 microchip technology inc. ds30569b-page 135 pic16f870/871 figure 14-13: a/d conversion timing table 14-10: a/d conversion requirements 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (t osc /2) (1) 987 210 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 1 t cy . . . . . . param no. sym characteristic min typ? max units conditions 130 t ad a/d clock period standard( f ) 1.6 ? ? st osc based, v ref 3.0v extended( lf )3.0?? st osc based, v ref 2.0v standard( f ) 2.0 4.0 6.0 s a/d rc mode extended( lf ) 3.0 6.0 9.0 s a/d rc mode 131 t cnv conversion time (not including s/h time) (note 1) ?12t ad 132 t acq acquisition time (note 2) 10* 40 ? ? ? s s the minimum time is the ampli- fier settling time. this may be used if the "new" input voltage has not changed by more than 1 lsb (i.e., 20.0 mv @ 5.12v) from the last sampled voltage (as stated on c hold ). 134 t go q4 to a/d clock start ? t osc /2 ? ? if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested. this specification ensured by design. note 1: adres register may be read on the following t cy cycle. 2: see section 10.1 for min conditions.
pic16f870/871 ds30569b-page 136 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 137 pic16f870/871 15.0 dc and ac characteristics graphs and tables ?typical? represents the mean of the distribution at 25c. ?maximum? or ?minim um? represents (mean + 3 ) or (mean - 3 ) respectively, where is a standard deviation, over the whole temperature range. figure 15-1: typical i dd vs. f osc over v dd (hs mode) figure 15-2: maximum i dd vs. f osc over v dd (hs mode) note: the graphs and tables provided following this note are a statistical summary based on a limited number of samples and are provided for informational purposes only. the performance characteristics listed herein are not tested or guaranteed. in some graphs or tables, the data presented may be outside the specified operating range (e.g., outside specified power supply range) and therefore, outside the warranted range. 0 1 2 3 4 5 6 7 4 6 8 101214161820 f osc (m h z ) i dd (ma) 2.5v 2.0v 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0 1 2 3 4 5 6 7 8 4 6 8 101214161820 f osc (m hz ) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f870/871 ds30569b-page 138 ? 2003 microchip technology inc. figure 15-3: typical i dd vs. f osc over v dd (xt mode) figure 15-4: maximum i dd vs. f osc over v dd (lp mode) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 0.00.51.01.52.02.53.03.54.0 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 2.5v 2.0v 3.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 2.5v 2.0v 3.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
? 2003 microchip technology inc. ds30569b-page 139 pic16f870/871 figure 15-5: typical i dd vs. f osc over v dd (lp mode) figure 15-6: maximum i dd vs. f osc over v dd (xt mode) 0 10 20 30 40 50 60 70 80 90 20 30 40 50 60 70 80 90 100 f osc (khz) i dd (ua) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0 10 20 30 40 50 60 70 80 90 100 110 120 20 30 40 50 60 70 80 90 100 f osc (khz) i dd (ua) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f870/871 ds30569b-page 140 ? 2003 microchip technology inc. figure 15-7: average f osc vs. v dd for various values of r (rc mode, c = 20 pf, 25 c) figure 15-8: average f osc vs. v dd for various values of r (rc mode, c = 100 pf, 25 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 2.02.53.03.54.04.55.05.5 v dd (v) freq (mhz) 3.3k ? 5.1k ? 10k ? 100k ? 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 3.3 k ? 5.1 k ? 10 k ? 100 k ?
? 2003 microchip technology inc. ds30569b-page 141 pic16f870/871 figure 15-9: average f osc vs. v dd for various values of r (rc mode, c = 300 pf, 25 c) figure 15-10: i pd vs. v dd (sleep mode, all peripherals disabled) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 3.3 k ? 5.1 k ? 10 k ? 100 k ? 0.01 0.10 1.00 10.00 100.00 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd ( a) max ( 12 5c) max ( 85 c) typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f870/871 ds30569b-page 142 ? 2003 microchip technology inc. figure 15-11: ? i bor vs. v dd over temperature figure 15-12: typical and maximum ? i tmr1 vs. v dd over temperature (-10 c to 70 c, timer1 with oscillator, xtal=32 khz, c1 and c2=50 pf) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 2.53.03.54.04.55.05.5 v dd (v) ? i (ma) device in sleep device in reset max reset typ reset (25c) ma x sleep ty p sleep ( 25 c) indeterminate state typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) note: device current in reset depends on oscillator mode, frequency and circuit. 0 10 20 30 40 50 60 70 80 90 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 vdd (v) ? itmr1 (ua) typ (25c) max typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
? 2003 microchip technology inc. ds30569b-page 143 pic16f870/871 figure 15-13: typical and maximum ? i wdt vs. v dd over temperature figure 15-14: typical, minimum and maximum wdt period vs. v dd (-40 c to 125 c) 0 2 4 6 8 10 12 14 2.02.53.03.54.04.55.05.5 v dd (v) ? i wdt (ua) typ (25c) max (85c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0 10 20 30 40 50 60 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) wdt period (ms) min (-40c) typ (25c) max (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f870/871 ds30569b-page 144 ? 2003 microchip technology inc. figure 15-15: average wdt period vs. v dd over temperature (-40 c to 125 c) figure 15-16: typical, minimum and maximum v oh vs. i oh (v dd = 5v, -40 c to 125 c) 0 5 10 15 20 25 30 35 40 45 50 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) wdt period (ms) 85c 125c 25c -40c typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 2.0 2.5 3.0 3.5 4.0 4.5 5.0 0 5 10 15 20 25 i oh (-ma) v oh (v) max (-40c) typ (25c) min (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
? 2003 microchip technology inc. ds30569b-page 145 pic16f870/871 figure 15-17: typical, minimum and maximum v oh vs. i oh (v dd = 3v, -40 c to 125 c) figure 15-18: typical, minimum and maximum v ol vs. i ol (v dd = 5v, -40 c to 125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 5 10 15 20 25 i oh (-ma) v oh (v) max (-40c) ty p (25c) min (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 0 5 10 15 20 25 i ol (-ma) v ol (v) max (125c) ty p (25c) min (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f870/871 ds30569b-page 146 ? 2003 microchip technology inc. figure 15-19: typical, minimum and maximum v ol vs. i ol (v dd = 3v, -40 c to 125 c) figure 15-20: minimum and maximum v in vs. v dd , (ttl input, -40 c to 125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 5 10 15 20 25 i ol (-ma) v ol (v) max (125c) typ (25c) min (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) max (-40c) min (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
? 2003 microchip technology inc. ds30569b-page 147 pic16f870/871 figure 15-21: minimum and maximum v in vs. v dd (st input, -40 c to 125 c) figure 15-22: minimum and maximum v in vs. v dd (i 2 c input, -40 c to 125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 2.02.53.03.54.04.55.05.5 v dd (v) v in (v) max high (125c) max low (125c) min high (-40c) min low (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 2.02.53.03.54.04.55.05.5 v dd (v) v in (v) max high (125c) max low (125c) min high (-40c) min low (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f870/871 ds30569b-page 148 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 149 pic16f870/871 16.0 packaging information 16.1 package marking information xxxxxxxxxxxxxxxxx yywwnnn 28-lead pdip (skinny dip) example xxxxxxxxxxxxxxxxx 0317017 pic16f870-i/sp 28-lead soic yywwnnn example xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx 0310017 pic16f870-i/so 28-lead ssop yywwnnn xxxxxxxxxxxx xxxxxxxxxxxx example 0320017 pic16f870-i/ss legend: xx...x customer specific information* y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line thus limiting the number of available characters for customer specific information. * standard picmicro device marking consists of microchip part number, year code, week code, and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price.
pic16f870/871 ds30569b-page 150 ? 2003 microchip technology inc. package marking information (cont?d) xxxxxxxxxxxxxxxxxx yywwnnn 40-lead pdip example xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx pic16f871-i/p 0312017 44-lead tqfp example xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn pic16f871 -i/pt 0320017 44-lead plcc example xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn pic16f871 -i/l 0320017
? 2003 microchip technology inc. ds30569b-page 151 pic16f870/871 28-lead skinny plastic dual in-line (sp) ? 300 mil (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 8.89 8.13 .430 .350 .320 eb overall row spacing 0.56 0.48 0.41 .022 .019 .016 b lower lead width 1.65 1.33 1.02 .065 .053 .040 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 35.18 34.67 34.16 1.385 1.365 1.345 d overall length 7.49 7.24 6.99 .295 .285 .275 e1 molded package width 8.26 7.87 7.62 .325 .310 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.43 3.30 3.18 .135 .130 .125 a2 molded package thickness 4.06 3.81 3.56 .160 .150 .140 a top to seating plane 2.54 .100 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d n e1 c eb e p l a2 b b1 a a1 notes: jedec equivalent: mo-095 drawing no. c04-070 * controlling parameter dimension d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. significant characteristic
pic16f870/871 ds30569b-page 152 ? 2003 microchip technology inc. 28-lead plastic small outline (so) ? wide, 300 mil (soic) foot angle top 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.33 0.28 0.23 .013 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 18.08 17.87 17.65 .712 .704 .695 d overall length 7.59 7.49 7.32 .299 .295 .288 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d p n b e e1 l c 45 h a2 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-013 drawing no. c04-052 significant characteristic
? 2003 microchip technology inc. ds30569b-page 153 pic16f870/871 28-lead plastic shrink small outline (ss) ? 209 mil, 5.30 mm (ssop) * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-150 drawing no. c04-073 10 5 0 10 5 0 mold draft angle bottom 10 5 0 10 5 0 mold draft angle top 0.38 0.32 0.25 .015 .013 .010 b lead width 203.20 101.60 0.00 8 4 0 foot angle 0.25 0.18 0.10 .010 .007 .004 c lead thickness 0.94 0.75 0.56 .037 .030 .022 l foot length 10.34 10.20 10.06 .407 .402 .396 d overall length 5.38 5.25 5.11 .212 .207 .201 e1 molded package width 8.10 7.85 7.59 .319 .309 .299 e overall width 0.25 0.15 0.05 .010 .006 .002 a1 standoff 1.83 1.73 1.63 .072 .068 .064 a2 molded package thickness 1.98 1.85 1.73 .078 .073 .068 a overall height 0.65 .026 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters* inches units 2 1 d p n b e1 e l c a2 a1 a significant characteristic
pic16f870/871 ds30569b-page 154 ? 2003 microchip technology inc. 40-lead plastic dual in-line (p) ? 600 mil (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 17.27 16.51 15.75 .680 .650 .620 eb overall row spacing 0.56 0.46 0.36 .022 .018 .014 b lower lead width 1.78 1.27 0.76 .070 .050 .030 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.05 .135 .130 .120 l tip to seating plane 52.45 52.26 51.94 2.065 2.058 2.045 d overall length 14.22 13.84 13.46 .560 .545 .530 e1 molded package width 15.88 15.24 15.11 .625 .600 .595 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 4.06 3.81 3.56 .160 .150 .140 a2 molded package thickness 4.83 4.45 4.06 .190 .175 .160 a top to seating plane 2.54 .100 p pitch 40 40 n number of pins max nom min max nom min dimension limits millimeters inches* units a2 1 2 d n e1 c eb e p l b b1 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: mo-011 drawing no. c04-016 significant characteristic
? 2003 microchip technology inc. ds30569b-page 155 pic16f870/871 44-lead plastic thin quad flatpack (pt) 10x10x1 mm body, 1.0/0.10 mm lead form (tqfp) * controlling parameter notes: dimensions d1 and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-026 drawing no. c04-076 1.14 0.89 0.64 .045 .035 .025 ch pin 1 corner chamfer 1.00 .039 (f) footprint (reference) (f) a a1 a2 e e1 #leads=n1 p b d1 d n 1 2 c l units inches millimeters* dimension limits min nom max min nom max number of pins n 44 44 pitch p .031 0.80 overall height a .039 .043 .047 1.00 1.10 1.20 molded package thickness a2 .037 .039 .041 0.95 1.00 1.05 standoff a1 .002 .004 .006 0.05 0.10 0.15 foot length l .018 .024 .030 0.45 0.60 0.75 foot angle 03.5 7 03.5 7 overall width e .463 .472 .482 11.75 12.00 12.25 overall length d .463 .472 .482 11.75 12.00 12.25 molded package width e1 .390 .394 .398 9.90 10.00 10.10 molded package length d1 .390 .394 .398 9.90 10.00 10.10 pins per side n1 11 11 lead thickness c .004 .006 .008 0.09 0.15 0.20 lead width b .012 .015 .017 0.30 0.38 0.44 mold draft angle top 51015 51015 mold draft angle bottom 51015 51015 ch x 45 significant characteristic
pic16f870/871 ds30569b-page 156 ? 2003 microchip technology inc. 44-lead plastic leaded chip carrier (l) ? square (plcc) ch2 x 45 ch1 x 45 10 5 0 10 5 0 mold draft angle bottom 10 5 0 10 5 0 mold draft angle top 0.53 0.51 0.33 .021 .020 .013 b 0.81 0.74 0.66 .032 .029 .026 b1 upper lead width 0.33 0.27 0.20 .013 .011 .008 c lead thickness 11 11 n1 pins per side 16.00 15.75 14.99 .630 .620 .590 d2 footprint length 16.00 15.75 14.99 .630 .620 .590 e2 footprint width 16.66 16.59 16.51 .656 .653 .650 d1 molded package length 16.66 16.59 16.51 .656 .653 .650 e1 molded package width 17.65 17.53 17.40 .695 .690 .685 d overall length 17.65 17.53 17.40 .695 .690 .685 e overall width 0.25 0.13 0.00 .010 .005 .000 ch2 corner chamfer (others) 1.27 1.14 1.02 .050 .045 .040 ch1 corner chamfer 1 0.86 0.74 0.61 .034 .029 .024 a3 side 1 chamfer height 0.51 .020 a1 standoff a2 molded package thickness 4.57 4.39 4.19 .180 .173 .165 a overall height 1.27 .050 p pitch 44 44 n number of pins max nom min max nom min dimension limits millimeters inches* units a2 c e2 2 d d1 n #leads=n1 e e1 1 p a3 a 35 b1 b d2 a1 .145 .153 .160 3.68 3.87 4.06 .028 .035 0.71 0.89 lower lead width * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: mo-047 drawing no. c04-048 significant characteristic
? 2003 microchip technology inc. ds30569b-page 157 pic16f870/871 appendix a: revision history revision a (december 1999) original data sheet for the pic16f870/871 family. revision b (april 2003) this revision includes the dc and ac characteristics graphs and tables. the electrical specifications in section 14.0 have been updated and there have been minor corrections to the data sheet text. appendix b: device differences the differences between the devices listed in this data sheet are shown in table b-1. table b-1: device differences feature pic16f870 pic16f871 on-chip program memory (kbytes) 2k 2k data memory (bytes) 128 128 boot block (bytes) 2048 512 timer1 low power option yes no i/o ports ports a, b, c ports a, b, c, d, e a/d channels 5 8 external memory interface no no package types 28-pin dip, soic, ssop 40-pin pdip, 44-pin plcc, tqfp
pic16f870/871 ds30569b-page 158 ? 2003 microchip technology inc. appendix c: conversion considerations this appendix discusses the considerations for con- verting from previous versions of a device to the ones listed in this data sheet. typically, these changes are due to the differences in the process technology used. an example of this type of conversion is from a pic17c756 to a pic18f8720. not applicable appendix d: migration from mid-range to enhanced devices a detailed discussion of the differences between the mid-range mcu devices (i.e., pic16cxxx) and the enhanced devices (i.e., pic18fxxx) is provided in an716, ?migrating designs from pic16c74a/74b to pic18c442.? the changes discussed, while device specific, are generally applicable to all mid-range to enhanced device migrations. this application note is available as literature number ds00716.
? 2003 microchip technology inc. ds30569b-page 159 pic16f870/871 appendix e: migration from high-end to enhanced devices a detailed discussion of the migration pathway and dif- ferences between the high-end mcu devices (i.e., pic17cxxx) and the enhanced devices (i.e., pic18fxxxx) is provided in an726, ?pic17cxxx to pic18cxxx migration.? this application note is available as literature number ds00726.
pic16f870/871 ds30569b-page 160 ? 2003 microchip technology inc. notes:
? 2003 microchip technology inc. ds30569b-page 161 pic16f870/871 index a a/d ...................................................................................... 79 acquisition requirements ........................................... 82 adcon0 register....................................................... 79 adcon1 register....................................................... 79 adif bit....................................................................... 80 adresh register....................................................... 79 adresl register ....................................................... 79 analog port pins ................................................... 41, 42 associated registers and bits .................................... 85 calculating acquisition time....................................... 82 configuring analog port pins...................................... 83 configuring the interrupt ............................................. 81 configuring the module............................................... 81 conversion clock........................................................ 83 conversions ................................................................ 84 delays ......................................................................... 82 effects of a reset ..................................................... 85 go/done bit.............................................................. 80 internal sampling switch (rss) impedance ................ 82 operation during sleep ............................................ 85 result registers.......................................................... 84 source impedance...................................................... 82 time delays ................................................................ 82 absolute maximum ratings .............................................. 117 adcon0 register............................................................... 13 adcon1 register............................................................... 14 adresh registers ............................................................. 13 adresl register ............................................................... 14 analog-to-digital converter. see a/d. application notes an552 (implementing wake-up on key stroke) ......... 35 an556 (implementing a table read) ......................... 24 assembler mpasm assembler................................................... 111 asynchronous reception associated registers .................................................. 69 asynchronous reception (9-bit mode) associated registers .................................................. 71 b banking, data memory ....................................................... 11 baud rate generator (brg) associated registers .................................................. 63 block diagrams a/d .............................................................................. 81 analog input model ..................................................... 82 capture mode operation ............................................ 56 compare mode operation .......................................... 57 interrupt logic ............................................................. 97 on-chip reset circuit .............................................. 91 pic16f870.................................................................... 5 pic16f871.................................................................... 6 portc (peripheral output override) ......................... 37 portd (in i/o port mode).......................................... 38 portd and porte (parallel slave port) .................. 42 porte (in i/o port mode).......................................... 39 pwm mode ................................................................. 58 ra3:ra0 and ra5 pins .............................................. 33 ra4/t0cki pin............................................................ 33 rb3:rb0 pins ............................................................. 35 rb7:rb4 pins ............................................................. 35 timer0/wdt prescaler ............................................... 45 timer1 ........................................................................ 50 timer2 ........................................................................ 53 usart asynchronous receive.................................. 68 usart asynchronous receive (9-bit mode) ............. 70 usart transmit ........................................................ 66 watchdog timer ......................................................... 99 bor. see brown-out reset. brgh bit ............................................................................ 63 brown-out reset (bor).................................... 87, 91, 92, 93 bor status (bor bit) ................................................ 23 c c compilers mplab c17.............................................................. 112 mplab c18.............................................................. 112 mplab c30.............................................................. 112 capture/compare/pwm (ccp) .......................................... 55 associated registers capture, compare and timer1........................... 59 pwm and timer2................................................ 60 capture mode............................................................. 56 ccp1if............................................................... 56 prescaler ............................................................ 56 ccp timer resources................................................ 55 compare special trigger output of ccp1 ......................... 57 compare mode........................................................... 57 software interrupt mode ..................................... 57 special event trigger ......................................... 57 pwm mode................................................................. 58 duty cycle .......................................................... 58 example frequencies/resolutions (table).......... 59 pwm period ....................................................... 58 setup for pwm operation .................................. 59 special event trigger and a/d conversions .............. 57 ccp. see capture/compare/pwm. ccp1con register............................................................ 13 ccp1m0 bit ........................................................................ 55 ccp1m1 bit ........................................................................ 55 ccp1m2 bit ........................................................................ 55 ccp1m3 bit ........................................................................ 55 ccp1x bit .......................................................................... 55 ccp1y bit .......................................................................... 55 ccpr1h register......................................................... 13, 55 ccpr1l register ......................................................... 13, 55 code examples changing between capture prescalers ..................... 56 eeprom data read.................................................. 29 eeprom data write .................................................. 29 flash program read................................................ 30 flash program write................................................ 31 indirect addressing..................................................... 24 initializing porta ...................................................... 33 saving status, w and pclath registers in ram................................................................ 98 code protected operation data eeprom and flash program memory ........... 31 code protection .......................................................... 87, 101 computed goto................................................................ 24 configuration bits ............................................................... 87 configuration word............................................................. 88 conversion considerations............................................... 158
pic16f870/871 ds30569b-page 162 ? 2003 microchip technology inc. d data eeprom .................................................................... 27 associated registers .................................................. 32 code protection .......................................................... 31 reading....................................................................... 29 spurious write protection ........................................... 31 write verify ................................................................. 31 writing to ..................................................................... 29 data memory....................................................................... 11 bank select (rp1:rp0 bits) ....................................... 11 general purpose registers......................................... 11 register file map ........................................................ 12 special function registers ......................................... 13 dc and ac characteristics graphs and tables................ 137 dc characteristics pic16f870/871 (extended) ...................................... 123 pic16f870/871 (industrial) ....................................... 121 pic16f870/871 (industrial, extended) and pic16lf870/871 (commercial, industrial)........ 119 demonstration boards picdem 1 ................................................................. 114 picdem 17 ............................................................... 114 picdem 18r pic18c601/801 .................................. 115 picdem 2 plus ......................................................... 114 picdem 3 pic16c92x ............................................. 114 picdem 4 ................................................................. 114 picdem lin pic16c43x ......................................... 115 picdem usb pic16c7x5........................................ 115 picdem.net internet/ethernet .................................. 114 development support ....................................................... 111 device differences ............................................................ 157 device overview ................................................................... 5 direct addressing................................................................ 25 e eeadr register ................................................................. 15 eeadrh register............................................................... 15 eecon1 register ......................................................... 15, 27 eecon2 register ......................................................... 15, 27 eedata register ............................................................... 15 eedath register ............................................................... 15 electrical characteristics................................................... 117 errata .................................................................................... 4 evaluation and programming tools .................................. 115 f firmware instructions........................................................ 103 flash program memory.................................................... 27 associated registers .................................................. 32 code protection .......................................................... 31 configuration bits and read/write state .................... 32 reading....................................................................... 30 spurious write protection ........................................... 31 write protection .......................................................... 32 write verify ................................................................. 31 writing to ..................................................................... 30 fsr register........................................................... 13, 14, 15 i i/o ports .............................................................................. 33 id locations ................................................................ 87, 101 in-circuit debugger ..................................................... 87, 101 in-circuit serial programming (icsp) ......................... 87, 102 indf register ......................................................... 13, 14, 15 indirect addressing ............................................................. 25 fsr register ........................................................ 11, 24 indf register ............................................................. 24 instruction descriptions .................................................... 105 instruction format............................................................. 103 instruction set................................................................... 103 addlw..................................................................... 105 addwf..................................................................... 105 andlw..................................................................... 105 andwf..................................................................... 105 bcf .......................................................................... 105 bsf........................................................................... 105 btfsc ...................................................................... 105 btfss ...................................................................... 105 call......................................................................... 106 clrf ........................................................................ 106 clrw ....................................................................... 106 clrwdt .................................................................. 106 comf ....................................................................... 106 decf ........................................................................ 106 decfsz ................................................................... 107 goto ....................................................................... 107 incf ......................................................................... 107 incfsz..................................................................... 107 iorlw ...................................................................... 107 iorwf...................................................................... 107 movf ....................................................................... 108 movlw .................................................................... 108 movwf .................................................................... 108 nop .......................................................................... 108 retfie ..................................................................... 108 retlw ..................................................................... 108 return................................................................... 109 rlf ........................................................................... 109 rrf .......................................................................... 109 sleep ...................................................................... 109 sublw ..................................................................... 109 subwf..................................................................... 109 swapf ..................................................................... 110 xorlw .................................................................... 110 xorwf .................................................................... 110 summary table ........................................................ 104 int interrupt (rb0/int). see interrupt sources. intcon .............................................................................. 15 intcon register.......................................................... 13, 15 gie bit ........................................................................ 18 inte bit ...................................................................... 18 intf bit ...................................................................... 18 peie bit ...................................................................... 18 rbie bit ...................................................................... 18 rbif bit ................................................................ 18, 35 t0ie bit ....................................................................... 18 internal sampling switch (rss) impedance........................ 82 interrupt sources .......................................................... 87, 96 interrupt-on-change (rb7:rb4) ................................. 35 rb0/int pin, external................................................. 97 tmr0 overflow........................................................... 97 usart receive/transmit complete .......................... 61 interrupts, context saving during....................................... 98
? 2003 microchip technology inc. ds30569b-page 163 pic16f870/871 interrupts, enable bits global interrupt enable (gie bit) .......................... 18, 96 interrupt-on-change (rb7:rb4) enable (rbie bit)...................................................... 18, 97 peripheral interrupt enable (peie bit) ........................ 18 rb0/int enable (inte bit) ......................................... 18 tmr0 overflow enable (t0ie bit)............................... 18 interrupts, flag bits interrupt-on-change (rb7:rb4) flag (rbif bit) ........................................ 18, 35, 97 rb0/int flag (intf bit).............................................. 18 tmr0 overflow flag (t0if bit) ................................... 97 l loading of pc ..................................................................... 24 low voltage in-circuit serial programming ................ 87, 102 m master clear (mclr ) mclr reset, normal operation ........................... 91, 93 mclr reset, sleep............................................ 91, 93 mclr /v pp /thv pin .......................................................... 7, 8 memory organization data memory .............................................................. 11 program memory ........................................................ 11 migration from high-end to enhanced devices ................ 159 migration from mid-range to enhanced devices ............. 158 mplab asm30 assembler, linker, librarian ................... 112 mplab icd 2 in-circuit debugger ................................... 113 mplab ice 2000 high performance universal in-circuit emulator .................................................... 113 mplab ice 4000 high performance universal in-circuit emulator .................................................... 113 mplab integrated development environment software............................................... 111 mplink object linker/mplib object librarian ................ 112 o opcode field descriptions ............................................. 103 option .............................................................................. 15 option register................................................................ 15 option_reg register ................................................ 14, 17 intedg bit ................................................................. 17 psa bit........................................................................ 17 rbpu bit..................................................................... 17 t0cs bit...................................................................... 17 t0se bit...................................................................... 17 osc1/clki pin ................................................................. 7, 8 osc2/clko pin ............................................................... 7, 8 oscillator configuration....................................................... 87 hs ......................................................................... 89, 92 lp.......................................................................... 89, 92 rc................................................................... 89, 90, 92 xt ......................................................................... 89, 92 oscillator, wdt ................................................................... 99 oscillators capacitor selection..................................................... 90 crystal and ceramic resonators ................................ 89 rc............................................................................... 90 p packaging ......................................................................... 149 marking information.................................................. 149 parallel slave port (psp).......................................... 9, 38, 42 associated registers.................................................. 43 re0/rd /an5 pin .................................................. 41, 42 re1/wr /an6 pin ................................................. 41, 42 re2/cs /an7 pin .................................................. 41, 42 select (pspmode bit) ............................. 38, 39, 40, 42 pcl register .................................................... 13, 14, 15, 24 pclath register ............................................. 13, 14, 15, 24 pcon register ....................................................... 14, 15, 92 bor bit....................................................................... 23 por bit....................................................................... 23 pickit 1 flash starter kit................................................ 115 picstart plus development programmer..................... 113 pie1 register ............................................................... 14, 15 pie2 register ............................................................... 14, 15 pinout descriptions pic16f870 ................................................................... 7 pic16f871 ................................................................... 8 pir1 register ..................................................................... 13 pir2 register ..................................................................... 13 pop .................................................................................... 24 por. see power-on reset. porta ............................................................................. 7, 8 associated registers.................................................. 34 porta register......................................................... 33 ra0/an0 pin ............................................................ 7, 8 ra1/an1 pin ............................................................ 7, 8 ra2/an2/v ref - pin ...................................................... 7 ra2/an2/v ref - pin ...................................................... 8 ra3/an3/v ref + pin ..................................................... 7 ra3/an3/v ref + pin ..................................................... 8 ra4/t0cki pin ......................................................... 7, 8 ra5/an4 pin ............................................................ 7, 8 trisa register........................................................... 33 porta register ................................................................. 13 portb ............................................................................. 7, 8 portb register......................................................... 35 pull-up enable (rbpu bit).......................................... 17 rb0/int edge select (intedg bit) ........................... 17 rb0/int pin.............................................................. 7, 8 rb0/int pin, external ................................................ 97 rb1 pin .................................................................... 7, 8 rb2 pin .................................................................... 7, 8 rb3/pgm pin ........................................................... 7, 8 rb4 pin .................................................................... 7, 8 rb5 pin .................................................................... 7, 8 rb6/pgc pin............................................................ 7, 8 rb7/pgd pin............................................................ 7, 8 rb7:rb4 interrupt-on-change ................................... 97 rb7:rb4 interrupt-on-change enable (rbie bit) ......................................... 18, 97 rb7:rb4 interrupt-on-change flag (rbif bit)........................................ 18, 35, 97 trisb register........................................................... 35 portb register ........................................................... 13, 15
pic16f870/871 ds30569b-page 164 ? 2003 microchip technology inc. portc.............................................................................. 7, 8 associated registers .................................................. 37 portc register ......................................................... 37 rc0/t1oso/t1cki pin ............................................ 7, 8 rc1/t1osi pin ......................................................... 7, 8 rc2/ccp1 pin .......................................................... 7, 8 rc3 pin..................................................................... 7, 8 rc4 pin..................................................................... 7, 8 rc5 pin..................................................................... 7, 8 rc6/tx/ck pin ................................................... 7, 8, 62 rc7/rx/dt pin ............................................. 7, 8, 62, 63 trisc register..................................................... 37, 61 portc register ................................................................. 13 portd............................................................................ 9, 42 associated registers .................................................. 38 parallel slave port (psp) function ............................. 38 portd register ......................................................... 38 rd0/psp0 pin .............................................................. 9 rd1/psp1 pin .............................................................. 9 rd2/psp2 pin .............................................................. 9 rd3/psp3 pin .............................................................. 9 rd4/psp4 pin .............................................................. 9 rd5/psp5 pin .............................................................. 9 rd6/psp6 pin .............................................................. 9 rd7/psp7 pin .............................................................. 9 trisd register........................................................... 38 portd register ................................................................. 13 porte.................................................................................. 9 analog port pins ................................................... 41, 42 associated registers .................................................. 41 input buffer full status (ibf bit) ................................. 40 input buffer overflow (ibov bit) ................................. 40 output buffer full status (obf bit)............................. 40 porte register ......................................................... 39 psp mode select (pspmode bit) ........... 38, 39, 40, 42 re0/rd /an5 pin............................................... 9, 41, 42 re1/wr /an6 pin .............................................. 9, 41, 42 re2/cs /an7 pin............................................... 9, 41, 42 trise register ........................................................... 39 porte register ................................................................. 13 postscaler, wdt assignment (psa bit) ................................................. 17 power-down mode. see sleep. power-on reset (por) ..................................... 87, 91, 92, 93 oscillator start-up timer (ost) ............................ 87, 92 por status (por bit)................................................. 23 power control (pcon) register ................................. 92 power-down (pd bit) .................................................. 91 power-up timer (pwrt) ...................................... 87, 92 time-out (to bit) ........................................................ 91 pr2 ..................................................................................... 15 pr2 register................................................................. 14, 53 prescaler, timer0 assignment (psa bit) ................................................. 17 pro mate ii universal device programmer ................... 113 product identification system............................................ 169 program counter reset conditions ...................................................... 93 program memory ................................................................ 11 interrupt vector ........................................................... 11 map and stack ............................................................ 11 paging ......................................................................... 24 reset vector............................................................. 11 program verification.......................................................... 101 programming, device instructions .................................... 103 pulse width modulation. see capture/compare/pwm, pwm mode. push.................................................................................. 24 r ram. see data memory. rcreg register ................................................................ 13 rcsta register ................................................................. 13 adden bit .................................................................. 62 cren bit .................................................................... 62 ferr bit..................................................................... 62 oerr bit .................................................................... 62 rx9 bit ....................................................................... 62 rx9d bit ..................................................................... 62 spen bit............................................................... 61, 62 sren bit .................................................................... 62 register file........................................................................ 11 register file map................................................................ 12 registers adcon0 (a/d control 0)............................................ 79 adcon1 (a/d control 1)............................................ 80 ccp1con (ccp control 1)........................................ 55 eecon1 (eeprom control 1) .................................. 28 intcon ...................................................................... 18 option_reg ...................................................... 17, 46 pcon (power control) ............................................... 23 pie1 (peripheral interrupt enable 1)........................... 19 pie2 (peripheral interrupt enable 2)........................... 21 pir1 (peripheral interrupt request flag 1) ................ 20 pir2 (peripheral interrupt request flag 2) ................ 22 rcsta (receive status and control) ........................ 62 status ..................................................................... 16 t1con (timer1 control) ............................................ 49 t2con (timer 2 control) ........................................... 53 trise ......................................................................... 40 txsta (transmit status and control) ........................ 61 reset ............................................................................ 87, 91 mclr reset. see mclr . reset conditions for all registers ........................... 93 reset conditions for pcon register....................... 93 reset conditions for program counter .................... 93 reset conditions for status register ................... 93 reset brown-out reset (bor). see brown-out reset (bor). power-on reset (por). see power-on reset (por). wdt reset. see watchdog timer (wdt). revision history................................................................ 157 s sci. see usart serial communication interface. see usart. sleep .................................................................. 87, 91, 100 software simulator (mplab sim) .................................... 112 software simulator (mplab sim30) ................................ 112 spbrg ............................................................................... 15 spbrg register................................................................. 14 special features of the cpu .............................................. 87 special function registers ................................................. 13 special function register summary .......................... 13 speed, operating.................................................................. 1 sspadd register............................................................... 15 sspstat register ............................................................. 15 stack................................................................................... 24 overflows.................................................................... 24 underflow ................................................................... 24
? 2003 microchip technology inc. ds30569b-page 165 pic16f870/871 status register ......................................................... 13, 15 pd bit.......................................................................... 91 to bit.......................................................................... 91 synchronous master reception associated registers .................................................. 75 synchronous master transmission associated registers .................................................. 73 synchronous slave reception associated registers .................................................. 77 synchronous slave transmission associated registers .................................................. 76 t t1ckps0 bit....................................................................... 49 t1ckps1 bit....................................................................... 49 t1con register ................................................................. 13 t1oscen bit ...................................................................... 49 t1sync bit......................................................................... 49 t2ckps0 bit....................................................................... 53 t2ckps1 bit....................................................................... 53 t2con register ................................................................. 13 t ad ...................................................................................... 83 time-out sequence............................................................. 92 timer0 ................................................................................. 45 associated registers .................................................. 47 clock source edge select (t0se bit)......................... 17 clock source select (t0cs bit).................................. 17 external clock............................................................. 46 interrupt....................................................................... 45 overflow enable (t0ie bit) ......................................... 18 overflow flag (t0if bit).............................................. 97 overflow interrupt ....................................................... 97 prescaler..................................................................... 46 t0cki.......................................................................... 46 timer1 ................................................................................. 49 associated registers .................................................. 52 asynchronous counter mode reading and writing to ....................................... 51 counter operation ...................................................... 50 incrementing edge (figure) ......................................... 50 operation in asynchronous counter mode................. 51 operation in synchronized counter mode.................. 50 operation in timer mode ............................................ 50 oscillator ..................................................................... 51 capacitor selection............................................. 51 prescaler..................................................................... 52 resetting of timer1 register pair (tmr1h, tmr1l) ............................................... 52 resetting timer1 using a ccp trigger output........... 51 tmr1h........................................................................ 51 tmr1l ........................................................................ 51 timer2 ................................................................................. 53 associated registers .................................................. 54 output ......................................................................... 54 postscaler ................................................................... 53 prescaler..................................................................... 53 prescaler and postscaler ............................................ 54 timing diagrams a/d conversion......................................................... 135 asynchronous master transmission........................... 67 asynchronous master transmission (back to back) .................................................... 67 asynchronous reception with address byte first .............................................. 71 asynchronous reception with address detect ................................................... 71 brown-out reset....................................................... 129 capture/compare/pwm (ccp1) .............................. 131 clko and i/o ........................................................... 128 external clock .......................................................... 126 parallel slave port (psp) read.................................. 43 parallel slave port (psp) write .................................. 43 reset, watchdog timer, oscillator start-up timer and power-up timer ................. 129 slow rise time (mclr tied to v dd ) ......................... 96 time-out sequence on power-up (mclr not tied to v dd ) case 1 ................................................................ 95 case 2 ................................................................ 95 time-out sequence on power-up (mclr tied to v dd ) ........................................... 95 timer0 and timer1 external clock ........................... 130 usart asynchronous reception .............................. 68 usart synchronous receive (master/slave) ......... 133 usart synchronous reception (master mode, sren) ........................................ 75 usart synchronous transmission ........................... 73 usart synchronous transmission (master/slave) .................................................. 133 wake-up from sleep via interrupt .......................... 101 timing parameter symbology .......................................... 125 tmr0 register.............................................................. 13, 15 tmr1cs bit........................................................................ 49 tmr1h register ................................................................. 13 tmr1l register.................................................................. 13 tmr1on bit ....................................................................... 49 tmr2 register.................................................................... 13 tmr2on bit ....................................................................... 53 toutps0 bit ...................................................................... 53 toutps1 bit ...................................................................... 53 toutps2 bit ...................................................................... 53 toutps3 bit ...................................................................... 53 trisa ................................................................................. 15 trisa register................................................................... 14 trisb ................................................................................. 15 trisb register............................................................. 14, 15 trisc ................................................................................. 15 trisc register................................................................... 14 trisd ................................................................................. 15 trisd register................................................................... 14 trise ................................................................................. 15 trise register................................................................... 14 ibf bit......................................................................... 40 ibov bit...................................................................... 40 obf bit ....................................................................... 40 pspmode bit .......................................... 38, 39, 40, 42 txreg register ................................................................. 13 txsta ................................................................................ 15 txsta register.................................................................. 14 brgh bit .................................................................... 61 csrc bit .................................................................... 61 trmt bit .................................................................... 61 tx9 bit........................................................................ 61 tx9d bit ..................................................................... 61 txen bit..................................................................... 61
pic16f870/871 ds30569b-page 166 ? 2003 microchip technology inc. u universal synchronous asynchronous receiver transmitter. see usart usart ................................................................................ 61 address detect enable (adden bit) .......................... 62 asynchronous mode ................................................... 66 asynchronous receive ............................................... 68 asynchronous receive (9-bit mode) ........................... 70 asynchronous receive with address detect. see asynchronous receive (9-bit mode). asynchronous reception ............................................ 69 asynchronous transmitter .......................................... 66 baud rate generator (brg)....................................... 63 baud rate formula............................................. 63 baud rates, asynchronous mode (brgh = 0) ................................................. 64 baud rates, asynchronous mode (brgh = 1) ................................................. 65 high baud rate select (brgh bit)..................... 61 sampling ............................................................. 63 clock source select (csrc bit) ................................. 61 continuous receive enable (cren bit) ..................... 62 framing error (ferr bit) ........................................... 62 overrun error (oerr bit) ........................................... 62 receive data, 9th bit (rx9d bit) ................................ 62 receive enable, 9-bit (rx9 bit) .................................. 62 serial port enable (spen bit)............................... 61, 62 single receive enable (sren bit) ............................. 62 synchronous master mode ......................................... 72 synchronous master reception .................................. 74 synchronous master transmission............................. 72 synchronous slave mode ........................................... 76 synchronous slave reception .................................... 77 synchronous slave transmit ...................................... 76 transmit data, 9th bit (tx9d)..................................... 61 transmit enable (txen bit)........................................ 61 transmit enable, nine-bit (tx9 bit) ............................ 61 transmit shift register status (trmt bit).................. 61 w wake-up from sleep................................................. 87, 100 interrupts .................................................................... 93 mclr reset ............................................................... 93 timing diagram ........................................................ 101 wdt reset ................................................................. 93 watchdog timer register summary ...................................................... 99 watchdog timer (wdt)................................................ 87, 99 enable (wdten bit)................................................... 99 postscaler. see postscaler, wdt. programming considerations ..................................... 99 rc oscillator............................................................... 99 time-out period .......................................................... 99 wdt reset, normal operation............................. 91, 93 wdt reset, sleep.............................................. 91, 93 write verify data eeprom and flash program memory ........... 31 www, on-line support .................... ................................... 4
? 2003 microchip technology inc. ds30569b-page 167 pic16f870/871 on-line support microchip provides on-line support on the microchip world wide web site. the web site is used by microchip as a means to make files and information easily available to customers. to view the site, the user must have access to the internet and a web browser, such as netscape ? or microsoft ? internet explorer. files are also available for ftp download from our ftp site. connecting to the microchip internet web site the microchip web site is available at the following url: www.microchip.com the file transfer site is available by using an ftp ser- vice to connect to: ftp://ftp.microchip.com the web site and file transfer site provide a variety of services. users may download files for the latest development tools, data sheets, application notes, user's guides, articles and sample programs. a vari- ety of microchip specific business information is also available, including listings of microchip sales offices, distributors and factory representatives. other data available for consideration is:  latest microchip press releases  technical support section with frequently asked questions  design tips  device errata  job postings  microchip consultant program member listing  links to other useful web sites related to microchip products  conferences for products, development systems, technical information and more  listing of seminars and events systems information and upgrade hot line the systems information and upgrade line provides system users a listing of the latest versions of all of microchip's development systems software products. plus, this line provides information on how customers can receive the most current upgrade kits.the hot line numbers are: 1-800-755-2345 for u.s. and most of canada, and 1-480-792-7302 for the rest of the world. 042003
pic16f870/871 ds30569b-page 168 ? 2003 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds30569b pic16f870/871 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2003 microchip technology inc. ds30569b-page 169 pic16f870/871 pic16f870/871 product identification system to order or obtain information, e.g. , on pricing or delivery, refer to the factory or the listed sales office. sales and support data sheets products supported by a preliminary data sheet may have an errata sheet describing minor operational differences and recommended workarounds. to determine if an errata sheet exists for a particular device, please contact one of the following: 1. your local microchip sales office 2. the microchip corporate literature center u.s. fax: (480) 792-7277 3. the microchip worldwide site (www.microchip.com) please specify which device, revision of silicon and data sheet (include literature #) you are using. new customer notification system register on our web site (www.microchip.com/cn) to receive the most current information on our products. part no. -x /xx xxx pattern package temperature range device device pic16f870, pic16f870t; v dd range 4.0v to 5.5v pic16f871, pic16f871t ; v dd range 4.0v to 5.5v pic16lf870x, pic16lf870t; v dd range 2.0v to 5.5v pic16lf871x, pic16lf871t; v dd range 2.0v to 5.5v f= normal v dd limits lp = extended v dd limits t = in tape and reel - soic, ssop, tqfp and plcc packages only. temperature range blank(3) = 0c to +70c (commercial) i = -40c to +85c (industrial) package pq = mqfp (metric pqfp) pt = tqfp (thin quad flatpack) so = soic sp = skinny plastic dip ss = ssop p=pdip l=plcc pattern qtp, code or special requirements (blank otherwise) examples: a) pic16f870-i/sp 301 = industrial temp., pdip package, 20 mhz, normal v dd limits, qtp pattern #301. b) pic16f871-i/pt = industrial temp., tqfp package, 20 mhz, extended v dd limits. c) pic16f871-i/p = industrial temp., pdip package, 20 mhz, normal v dd limits. d) pic16lf870-i/ss = industrial temp., ssop package, dc - 20 mhz, extended v dd limits.
ds30569b-page 170 ? 2003 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: 480-792-7627 web address: http://www.microchip.com atlanta 3780 mansell road, suite 130 alpharetta, ga 30022 tel: 770-640-0034 fax: 770-640-0307 boston 2 lan drive, suite 120 westford, ma 01886 tel: 978-692-3848 fax: 978-692-3821 chicago 333 pierce road, suite 180 itasca, il 60143 tel: 630-285-0071 fax: 630-285-0075 dallas 4570 westgrove drive, suite 160 addison, tx 75001 tel: 972-818-7423 fax: 972-818-2924 detroit tri-atria office building 32255 northwestern highway, suite 190 farmington hills, mi 48334 tel: 248-538-2250 fax: 248-538-2260 kokomo 2767 s. albright road kokomo, in 46902 tel: 765-864-8360 fax: 765-864-8387 los angeles 18201 von karman, suite 1090 irvine, ca 92612 tel: 949-263-1888 fax: 949-263-1338 phoenix 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7966 fax: 480-792-4338 san jose microchip technology inc. 2107 north first street, suite 590 san jose, ca 95131 tel: 408-436-7950 fax: 408-436-7955 toronto 6285 northam drive, suite 108 mississauga, ontario l4v 1x5, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia microchip technology australia pty ltd marketing support division suite 22, 41 rawson street epping 2121, nsw australia tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing microchip technology consulting (shanghai) co., ltd., beijing liaison office unit 915 bei hai wan tai bldg. no. 6 chaoyangmen beidajie beijing, 100027, no. china tel: 86-10-85282100 fax: 86-10-85282104 china - chengdu microchip technology consulting (shanghai) co., ltd., chengdu liaison office rm. 2401-2402, 24th floor, ming xing financial tower no. 88 tidu street chengdu 610016, china tel: 86-28-86766200 fax: 86-28-86766599 china - fuzhou microchip technology consulting (shanghai) co., ltd., fuzhou liaison office unit 28f, world trade plaza no. 71 wusi road fuzhou 350001, china tel: 86-591-7503506 fax: 86-591-7503521 china - hong kong sar microchip technology hongkong ltd. unit 901-6, tower 2, metroplaza 223 hing fong road kwai fong, n.t., hong kong tel: 852-2401-1200 fax: 852-2401-3431 china - shanghai microchip technology consulting (shanghai) co., ltd. room 701, bldg. b far east international plaza no. 317 xian xia road shanghai, 200051 tel: 86-21-6275-5700 fax: 86-21-6275-5060 china - shenzhen microchip technology consulting (shanghai) co., ltd., shenzhen liaison office rm. 1812, 18/f, building a, united plaza no. 5022 binhe road, futian district shenzhen 518033, china tel: 86-755-82901380 fax: 86-755-82966626 china - qingdao rm. b505a, fullhope plaza, no. 12 hong kong central rd. qingdao 266071, china tel: 86-532-5027355 fax: 86-532-5027205 india microchip technology inc. india liaison office marketing support division divyasree chambers 1 floor, wing a (a3/a4) no. 11, o?shaugnessey road bangalore, 560 025, india tel: 91-80-2290061 fax: 91-80-2290062 japan microchip technology japan k.k. benex s-1 6f 3-18-20, shinyokohama kohoku-ku, yokohama-shi kanagawa, 222-0033, japan tel: 81-45-471- 6166 fax: 81-45-471-6122 korea microchip technology korea 168-1, youngbo bldg. 3 floor samsung-dong, kangnam-ku seoul, korea 135-882 tel: 82-2-554-7200 fax: 82-2-558-5934 singapore microchip technology singapore pte ltd. 200 middle road #07-02 prime centre singapore, 188980 tel: 65-6334-8870 fax: 65-6334-8850 taiwan microchip technology (barbados) inc., taiwan branch 11f-3, no. 207 tung hua north road taipei, 105, taiwan tel: 886-2-2717-7175 fax: 886-2-2545-0139 europe austria microchip technology austria gmbh durisolstrasse 2 a-4600 wels austria tel: 43-7242-2244-399 fax: 43-7242-2244-393 denmark microchip technology nordic aps regus business centre lautrup hoj 1-3 ballerup dk-2750 denmark tel: 45-4420-9895 fax: 45-4420-9910 france microchip technology sarl parc d?activite du moulin de massy 43 rue du saule trapu batiment a - ler etage 91300 massy, france tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany microchip technology gmbh steinheilstrasse 10 d-85737 ismaning, germany tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy microchip technology srl via quasimodo, 12 20025 legnano (mi) milan, italy tel: 39-0331-742611 fax: 39-0331-466781 united kingdom microchip ltd. 505 eskdale road winnersh triangle wokingham berkshire, england rg41 5tu tel: 44-118-921-5869 fax: 44-118-921-5820 03/25/03 w orldwide s ales and s ervice


▲Up To Search▲   

 
Price & Availability of PIC16F871T-EL

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X